[Zope] File uploading

Oliver Bleutgen myzope@gmx.net
Tue, 10 Sep 2002 19:44:51 +0200


Pawel Lewicki wrote:
> Hallo,
> I have 2 forms in my CMF site (but I suppose that is not a problem). Both of
> them have
>  <input name="image_file" type="file" >
> field. I try to get the file name to add a file(image) with proper id.
> When I access str(REQUEST.image_file) in my python script one time I get the
> full path to the file and the second time:
> <ZPublisher.HTTPRequest.FileUpload instance at 020CF314>
> The first one is better for me for explained reason but the files seem not
> to be uploading. So it is probably just a name not a file.
> The first question is where is the difference? It's probably in the code but
> I can't find it. I don't know much about HTTP protocol but the first thing
> to check was the type of forms - both are "POST" type.
> And the second - how to extract the name of the file and have it uploaded in
> the same time?
> 
> Pawel Lewicki


your_target_to_add_image.manage_addImage('',image_file)
should do the trick, it causes zope to construct the id itself (see 
OFS/Image.py, the method is called CookId) from the filename.

Additionally, image_file.filename gives you the filename of the uploaded 
file, but you might have to strip off the leading path.


HTH,
oliver