[Zope] Storing files externally
Nick Garcia
ngarcia@codeit.com
Fri, 17 Dec 1999 14:55:33 -0800
Alexander Limi wrote:
>
> Zopistas,
>
> I'm trying to store files that are submitted from a form on the local
> filesystem, and not in the ZODB. First, I thought I could use the LocalFS
> product, but this is read only, so no dice.
>
> Then I tried to implement the things I found in the "Howto store files
> externally"-howto. I'm almost there (after some fiddling around, the howto is a
> bit lacking) but I get errors.
>
> Shouldn't it be easy to store files outside the ZODB? I find these methods a
> bit cumbersome.
>
> Alexander Limi.
> http://mp3.no
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.
There's normally some processing that goes on between the readlines()
and the writelines(), but I cut all that out so you could see the
basics.
--
Nick Garcia | ngarcia@codeit.com
CodeIt Computing | http://codeit.com