Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6202545
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 24, 20262026-05-24T04:45:15+00:00 2026-05-24T04:45:15+00:00

Tried to use the following code, but it doesn’t work properly: // download the

  • 0

Tried to use the following code, but it doesn’t work properly:

  // download the file first
  var req = new XMLHttpRequest();
  req.open('GET', url, false);
  req.overrideMimeType('text/plain; charset=x-user-defined');
  req.send(null);
  if (req.status != 200) return '';

  // upload the file
  req.open("POST", "http://mysite.com/upload", false);
  req.setRequestHeader("Content-Length", req.responseText.length);
  req.sendAsBinary(req.responseText); // What should I pass here?

  if (req.status != 200) return '';
  return req.responseText;

sendAsBinary is firefox function.

Upd. Also I’ve tried to upload that as part of the form:

var response = req.responseText;
var formData = new FormData();
formData.append("file", response);
req.open("POST", "http://mysite.com/upload", false);
req.send(formData);

But still not full data is received by the server.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-24T04:45:16+00:00Added an answer on May 24, 2026 at 4:45 am

    Finally I’ve used the approach with temp file:

      var downloadCompleted = false;
    
      // download the file first
      var persist = Components.classes["@mozilla.org/embedding/browser/nsWebBrowserPersist;1"]
                      .createInstance(Components.interfaces.nsIWebBrowserPersist);
      // get OS temp folder
      var file = Components.classes["@mozilla.org/file/directory_service;1"]
                    .getService(Components.interfaces.nsIProperties)
                    .get("TmpD", Components.interfaces.nsIFile);
      file.append("temp.ext");
      file.createUnique(Components.interfaces.nsIFile.NORMAL_FILE_TYPE, 0666);
    
      var fURI = Services.io.newURI(url,null,null);
        const nsIWBP = Components.interfaces.nsIWebBrowserPersist;
        const flags = nsIWBP.PERSIST_FLAGS_REPLACE_EXISTING_FILES;
        persist.persistFlags = flags | nsIWBP.PERSIST_FLAGS_FROM_CACHE;
    
      persist.progressListener = {
        onProgressChange: function(aWebProgress, aRequest, aCurSelfProgress, aMaxSelfProgress, aCurTotalProgress, aMaxTotalProgress) {
          },
        onStateChange: function(aWebProgress, aRequest, aStateFlags, aStatus) {
          if (aStateFlags & Components.interfaces.nsIWebProgressListener.STATE_STOP) {
             downloadCompleted = true; // file has been downloaded        
          }
        }
      }
      persist.saveURI(fURI, null, null, null, "", file);  
    
      var thread = Components.classes["@mozilla.org/thread-manager;1"]
                            .getService(Components.interfaces.nsIThreadManager)
                            .currentThread;
      while (!downloadCompleted) // emulate synchronous request, not recommended approach
        thread.processNextEvent(true); 
    
      // upload the file
      var stream = Components.classes["@mozilla.org/network/file-input-stream;1"]
                           .createInstance(Components.interfaces.nsIFileInputStream);
      stream.init(file, 0x04 | 0x08, 0644, 0x04); // file is an nsIFile instance   
    
      // try to determine the MIME type of the file
      var mimeType = "text/plain";
      try {
        var mimeService = Components.classes["@mozilla.org/mime;1"]
                .getService(Components.interfaces.nsIMIMEService);
        mimeType = mimeService.getTypeFromFile(file); // file is an nsIFile instance
      }
      catch(e) { /* just use text/plain */ }
    
      var req = Components.classes["@mozilla.org/xmlextras/xmlhttprequest;1"]
                          .createInstance(Components.interfaces.nsIXMLHttpRequest);
      req.open('POST', "http://mysite.com/upload", false); 
      req.setRequestHeader('Content-Type', mimeType);
      req.send(stream);
    
      // delete the file
      file.remove(false);
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I use the following code to set markers on my map: var latLngs =
I tried to use DriveInfo.IsReady, but it returns false if an unformatted floppy is
What should i use to code Classic ASP under Linux. I have really tried
I'm trying to use the following code to make an image fadeOut and, only
I tried to use this on my class library mylib.core.data.dll and got a successful
I tried to use OPTION (MAXRECURSION 0) in a view to generate a list
I have tried to use ASP.NET MVC for a while, then I face a
Has anybody tried to use JavaFX Script in server side applications? The language itself
I have tried to use some of the widgets in JQuery UI on an
I have a DLL that I want to profile.. I tried to use Very

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.