[Zope] Storing files externally

Alexander Limi alexander@limi.net
Sat, 18 Dec 1999 01:08:55 +0100


> Hi Alex, I just use a simple external method for this purpose.  I have a
> form that has a file input box called "file".  The form posts to this
> external method using method="post" and enctype="multipart/form-data".
>
> It's a small function, so I'll just post the code here:
>
> def processFile(self, file, REQUEST=None, RESPONSE=None):
>
>     buffer = file.readlines()
>
>     outfile = open('%s/new_data.txt' % ATTACHMENTS_HOME, 'w')
>     outfile.writelines(buffer)
>
>     if REQUEST is not None:
>         return RESPONSE.redirect('%s/updated.html' % REQUEST['URL1'])
>
> ATTACHMENTS_HOME is a variable I define elsewhere in the module.  After
> the file is saved, I just have it redirect to a page called
> updated.html.

This _almost_ does the trick. Text files work fine, but GIFs do not. I suspect
it may be because the buffer processing adds something to the data - in any
case the file is garbled in the other end. The size of the file is not correct,
in one particular case the original file was 5627 bytes, the processed file was
5654 bytes, ie. it ends up being 27 bytes larger than the original.

Any suggestions? The enc-type is multipart/form-data.

Alexander Limi
http://mp3.no