Thank you to anyone who has already donated - your generous donations helped make three months of treatment possible.
My brother Nate continues to fight stage IV Hodgkin's lymphoma. He's just 31, with a wife and baby girl. They have no active income (since he's been unable to return to work), no insurance, and cannot afford the treatment he needs. Nate and his family need your help. Please consider a donation, every dollar helps. Thanks.
startUploading: function() {
this.info.label = 'Started with uploading ...';
var data = '';
var istream = Components.classes['@mozilla.org/network/file-input-stream;1']
.createInstance(Components.interfaces.nsIFileInputStream);
var bstream = Components.classes["@mozilla.org/binaryinputstream;1"]
.createInstance(Components.interfaces.nsIBinaryInputStream);
istream.init(this.file, -1, -1, false);
bstream.setInputStream(istream);
data = bstream.readBytes(bstream.available());
var boundaryString = 'dropio-boundary' + Math.random();
var boundary = '--' + boundaryString;
// create a string input stream with the form preamble
var prefixStringInputStream = Components.classes["@mozilla.org/io/string-input-stream;1"].createInstance(Components.interfaces.nsIStringInputStream);
var formData =
boundary + '\n'
+ 'Content-Disposition: form-data; name="file"; filename="water_fire.png"' + '\n'
+ 'Content-Type: image/png' + '\n\n';
prefixStringInputStream.setData(formData, formData.length);
// write the image data via a binary output stream, to a storage stream
var binaryOutputStream = Components.classes["@mozilla.org/binaryoutputstream;1"].createInstance(Components.interfaces.nsIBinaryOutputStream);
var storageStream = Components.classes["@mozilla.org/storagestream;1"].createInstance(Components.interfaces.nsIStorageStream);
storageStream.init(4096, data.length, null);
binaryOutputStream.setOutputStream(storageStream.getOutputStream(0));
binaryOutputStream.writeBytes(data, data.length);
binaryOutputStream.close();
// write out the rest of the form to another string input stream
var suffixStringInputStream = Components.classes["@mozilla.org/io/string-input-stream;1"]
.createInstance(Components.interfaces.nsIStringInputStream);
formData = '\n' + boundary + '\n';
suffixStringInputStream.setData(formData, formData.length);
// multiplex the streams together
var multiStream = Components.classes["@mozilla.org/io/multiplex-input-stream;1"].createInstance(Components.interfaces.nsIMultiplexInputStream);
multiStream.appendStream(prefixStringInputStream);
multiStream.appendStream(storageStream.newInputStream(0));
multiStream.appendStream(suffixStringInputStream);
// post it
var req = new XMLHttpRequest();
req.open('POST', 'http://localhost:3000/buckets');
req.setRequestHeader('Content-Type', 'multipart/form-data; boundary=' + boundaryString);
req.setRequestHeader('Content-Length', multiStream.available());
req.send(multiStream);
},
|