nsIUploadChannel and nsIFileChannel

1 view
Skip to first unread message

Matthew Buckett

Jan 3, 2003, 11:02:52 AM1/3/03
I'm trying to get some code that allows saving of some data
(http/ftp/file URLs) and it works for nsIHttpChannel and nsIFtpChannel
but nsIFileChannel doesn't seem to like it. I get no file created and an
error of 0x8000ffff.

Here's the code:

var dataString = "This is a test string\n";

var ioService = Components.classes[

var nsIURI Components.classes[

nsIURI.spec = "file:///tmp/test.file";

var ioChannel = ioService.newChannelFromURI(nsIURI);
var destChannel = ioChannel.QueryInterface(

var uploadChannel = destChannel.QueryInterface(

var postStream = Components.classes[

postStream.setData(dataString, dataString.length);
uploadChannel.setUploadStream(postStream, "text/plain", -1);

uploadChannel.asyncOpen(listener, null);

Thank you for any help.

Matthew Buckett

Boris Zbarsky

Jan 3, 2003, 12:26:07 PM1/3/03
to Matthew Buckett, mozilla...@mozilla.org
> var nsIURI Components.classes[
> "@mozilla.org/network/standard-url;1"
> ].createInstance(Components.interfaces.nsIURI);
> nsIURI.spec = "file:///tmp/test.file";

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.

Ray's Rule of Precision:
Measure with a micrometer. Mark with chalk. Cut
with an axe.

Reply all
Reply to author
0 new messages