file = files.getNext() .QueryInterface(Components.interfaces.nsILocalFile); jsFile = new File(file.path); // JSLib file jsFile.open();
Er... why not just create an input stream here?
var sData = "clientfile=" + encodeURIComponent( jsFile.read() );
This almost certainly messes up the data. Also, this is NOT how files are sent when POST is used. They're sent as raw binary data.
var req = new XMLHttpRequest; req.open("POST", "http://server/filehandler", false); req.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
That's the wrong content type. You want to use multipart/form-data. Note that that's the type you put on your <form> tag!
Then I've tried using nsIUploadChannel, so the previous while loop is like:
I suggest you look into what nsFSMultipartFormData::AddNameFilePair (the C++ implementation of POST forms) does. It's using an nsIMultiplexInputStream to interleave the strings you need for a multipart document with the actual data (whether string or file). It's also using an nsIMIMEInputStream to provide the content-length, etc headers that HTTP needs to do this right.
Both of those interfaces are scriptable; you shouldn't have any real trouble duplicating what the C++ does in JS.
-Boris _______________________________________________ Mozilla-netlib mailing list Mozilla-netlib@mozilla.org http://mail.mozilla.org/listinfo/mozilla-netlib