----- Original Message ----
> From: Gil Binder <gbi...@gmail.com>
> To: dev-ext...@lists.mozilla.org
> Sent: Thursday, October 9, 2008 8:57:39 PM
> Subject: Send a file - http
>
> Hello everyone,
>
> I am trying to develop an extension that sends a file to a remote
> server->(running apache+mod_python).
> How can this be done?
>
A few ways, but XmlHttpRequest might be the easiest. Search developer.mozilla.org for great docs on it.
Eric
> > A few ways, but XmlHttpRequest might be the easiest. Search
> developer.mozilla.org for great docs on it.
> >
> > Eric
>
> Interesting, thank you Eric.
>
> Indeed I can use XmlHttpRequest for the data sending, but how would I
> go about getting the local file and sending it using the
> XmlHttpRequest object?
>
You didn't specify if you want to prompt the user for the filename or what, but have a look here:
http://developer.mozilla.org/en/Code_snippets/File_I%2f%2fO
for all sorts of info on reading local files as well as prompting the user for the filename.
Eric
Have a look at nsIUploadChannel if you plan to deal with "large"
uploads. (Those regular HTTP channels implement that
interface/functionality).
http://mxr.mozilla.org/seamonkey/source/netwerk/base/public/nsIUploadChannel.idl
http://mxr.mozilla.org/seamonkey/source/netwerk/base/public/nsIFileStreams.idl
See the HTTP and MIME specs on how to send the data in a format your app
may understand.
If you need to send some string data and some data retrieved from a file
combined (like it is with multipart/form-data) have a look at
nsIMultiplexInputStream too.
http://mxr.mozilla.org/seamonkey/source/xpcom/io/nsIMultiplexInputStream.idl
The critical parts for multipart/form-data file submissions are located
here btw:
http://mxr.mozilla.org/seamonkey/source/content/html/content/src/nsFormSubmission.cpp#777
If it is just some "small" files then you might use
XMLHttpRequest.send(data) (this will internally use nsIUploadChannel
anyway).
You may also manipulate the XMLHttpRequest channel yourself (should
support things like e.g.
nsIHttpChannel/nsIUploadChannel/nsIResumableChannel).
http://mxr.mozilla.org/seamonkey/source/content/base/public/nsIXMLHttpRequest.idl
Cheers
Nils