1

I'm trying desperately to create a Firefox add-on that posts a file with the field name "Filedata" to a particular PHP script which will only work if it sees a JPG in the $_FILE["Filedata"] variable.

I put a web form with a file browser into panel.html, then I take the image and turn it into a canvas which I turn into a blob and send to main.js. I would be happy to send the file directly from panel.js, but nothing at all happens (no error message either) when I attempt to so.

In main.js, I have this code but I get an error message that FormData doesn't exist in main.js. What to do?

function ajupload(mydata) {
var fd = new FormData();
fd.append("Filedata", mydata);
const {XMLHttpRequest} = require("sdk/net/xhr");
var myrequest = new XMLHttpRequest();
 myrequest.open('POST', 'MYSITE/image.php?action=upload');myrequest.setRequestHeader("Content-type","application/x-www-form-urlencoded");
    myrequest.upload.addEventListener("progress", function(e) {

    var percentage = Math.round((e.loaded * 100) / e.total);
}, false);
myrequest.onreadystatechange=function()
  {
  if (myrequest.readyState==4 && myrequest.status==200)
    {
    console.log("Response" + myrequest.responseText);
    }

    }
myrequest.send(fd);
}
  • 1
    A lot of topics in this firefox-addon section on how to upload. I asked one too, check them out: http://stackoverflow.com/search?q=[firefox-addon]+upload here is my topic: http://stackoverflow.com/questions/22036442/upload-image-binary-using-imageshack-api?s=9|2.8196 here is another topic: http://stackoverflow.com/questions/13900527/how-to-upload-binary-content-with-firefox-extension?s=6|3.1269 – Noitidart Mar 20 '15 at 03:27

0 Answers0