[Zope] upload file from filename

Max M maxm@mxm.dk
Fri, 01 Mar 2002 14:55:51 +0000


John Hunter wrote:

>>>>>>"John" == John Ziniti <jziniti@speakeasy.org> writes:
>>>>>>
>    John> You really need to send in the "filename" as the value of a
>    John> browser "<input type=file>" form element.  In short, the
>    John> file name is not enough info ... the form element passes in
>    John> a file handle as well, allowing the upload.
>
>Yes, I've been reading some of the HTTPRequest source code to try and
>figure out how this is done, but no luck yet.  If anyone knows how to
>construct this object from a filename/path etc so that it could be
>used with manage_addFile, I would be much obliged.
>

Hmmm ... this is non-trivial. I must admit that I have never tried to 
send stuff this way, But I have looked over the spec for parsing it at 
the server side, and though it is really not *that* difficult, it is not 
too easy either.

There are 3 ways to send data to a webserver: urlencoded (method="get"), 
"application/x-www-form-encoded" (method="post") and multipart/form-data 
(enctype="multipart/form-data" method="post").

It is the latter that is of interrest to you. As far as I can tell it is 
a form of mime data. So the Mime module is probably where you should 
look for a solution.

Then you will need to do a "post", probably with some special headers 
and the content of the form as a mime message.

I don't believe that you can use the standard urllib or even urllib2 as 
they only handle data of the "application/x-www-form-encoded " and 
"urlencoded" type.

Hopes it gives a push in the right direction.

regards Max M