[Zope] Problem with file upload

Rob Page rob.page@digicool.com
Thu, 22 Jul 1999 12:16:19 -0400


> I don't have error, I don't understand what the browser do, 
> and what I must do to get the uploaded file with a python script.
> And overall, what must do my python script (parameters, etc...)
> 
> If you could explain me, I thank you very much !

Here is a snippet of code I found on a recent project we did...  This is
in an External Method emSaveAttachment

from Globals import MessageDialog
import os
import re
import string
ATTACHMENTS_HOME = "/export/local/dc/attachments/"
def saveAttachment(self, action_id, file, REQUEST=None, RESPONSE=None):
    attachment_dir = _makeAttachmentDir(ATTACHMENTS_HOME, action_id)
    
    buffer = file.read(8192)
    if len(buffer) > 0:                 
        # We do not save empty files. If the file is empty it's probably
        # because the file name is invalid!
        of = open(_makeAttachmentName(attachment_dir, file), "w")
        while buffer:
            of.write(buffer)
            buffer = file.read(8192)
        of.close()

Which is called from this document snippet which collects the file...

<FORM ACTION="emSaveAttachment" METHOD="POST"
 ENCTYPE="multipart/form-data">

<input type="hidden" name="action_id" value="<!--#var action_id-->">
File Name: <input type=file name=file size=25><br>
<input type="submit">
</form>

HTH,
--Rob