My Firefox addon downloaded the file and开发者_高级运维 saved that at temp folder. In result I have nsIFile instance.
How can I upload that file to another server? If I use XMLHttpRequest, I don't understand how to pass that nsIFile
to FormData
.
Or, probably I shouldn't just download the file and save that in the temp folder - since the only usage of this file is to be uploaded to another server. Probably, I should keep the file (file size ~20Kb) in the memory?
If you are POSTing the data to the server as application/x-www-form-urlencoded then you should base64 encode it using btoa() and include it as one of the POST parameters in the request body (i.e. the string passed to XMLHttpRequest.send()):
postbody = "body=" + btoa(fileContents);
xhr.send(postbody);
I agree that if you are just downloading the file and uploading it right away, you might as well keep it in memory since you're presumably going to load it into memory anyway in order to base64 encode the contents.
精彩评论