Here's the code:
var dataString = "This is a test string\n";
var ioService = Components.classes[
"@mozilla.org/network/io-service;1"
].getService(Components.interfaces.nsIIOService);
var nsIURI Components.classes[
"@mozilla.org/network/standard-url;1"
].createInstance(Components.interfaces.nsIURI);
nsIURI.spec = "file:///tmp/test.file";
var ioChannel = ioService.newChannelFromURI(nsIURI);
var destChannel = ioChannel.QueryInterface(
Components.interfaces.nsIFileChannel
);
var uploadChannel = destChannel.QueryInterface(
Components.interfaces.nsIUploadChannel
);
var postStream = Components.classes[
"@mozilla.org/io/string-input-stream;1"
].createInstance(Components.interfaces.nsIStringInputStream);
postStream.setData(dataString, dataString.length);
uploadChannel.setUploadStream(postStream, "text/plain", -1);
uploadChannel.asyncOpen(listener, null);
Thank you for any help.
Matthew Buckett
This is the wrong way to create a URI and in particular it creates a file://
uri that does not know that it's a file uri (does not QI to nsIFileURL).
You want to use nsIIoService::newURI to create the URI object.
Boris
--
Ray's Rule of Precision:
Measure with a micrometer. Mark with chalk. Cut
with an axe.