[Zope] Storing files externally

Nick Garcia ngarcia@codeit.com
Fri, 17 Dec 1999 16:37:50 -0800


Alexander Limi wrote:
> 
> > 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.

Change this line:

outfile = open('%s/new_data.txt' % ATTACHMENTS_HOME, 'wb')

This will open the file for writing binary data.  Should work fine for
text too.

-- 
Nick Garcia | ngarcia@codeit.com
CodeIt Computing | http://codeit.com