[Zope] Storing files externally

Li Dongfeng mavip5@inet.polyu.edu.hk
Sat, 18 Dec 1999 12:10:47 +0800


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

If the file is GIF, then you shouldn't use readlines(),
because there are no lines.
And as the other postings suggested, the output file
should be opened with the 'wb' flag.

Note a problem might arise in writing to a external file:
Be sure to avoid conflict.
If two persons are submitting the same form and the external
method want to write to the same file, there will be a problem.


> Alexander Limi
> http://mp3.no
> 
> _______________________________________________
> Zope maillist  -  Zope@zope.org
> http://lists.zope.org/mailman/listinfo/zope
> **   No cross posts or HTML encoding!  **
> (Related lists -
>  http://lists.zope.org/mailman/listinfo/zope-announce
>  http://lists.zope.org/mailman/listinfo/zope-dev )