[Zope] Re: Problems using forms to upload files to Zope

Mike Jakowlew mjakowlew at gmail.com
Tue Nov 15 13:19:14 EST 2005


Okay I corrected:

<form action="uploadForm.py" method="post" enctype="multipart/form-data">

and also tried the getContentType, but I get the error:

*Error Type: AttributeError*
*Error Value: FileUpload instance has no attribute 'getContentType'

****uploadForm.py****
def content_type(self):
return self.getContentType()

def writeDB():
# get sql method
insert=container['insert_fileapps']

REQUEST=context.REQUEST

department = REQUEST.form.get('department')
title = REQUEST.form.get('title')
filename = REQUEST.form.get('upload_filename')

upload_contents= content_type(filename)

if content_type.find('image')!=-1:
context.manage_addImage(id, file, title)
else:
context.manage_addFile(id, file, title)
return 'Finished'

version = REQUEST.form.get('version')
url = REQUEST.form.get('url')
ownerapp = REQUEST.form.get('ownerapp')
isoapp = REQUEST.form.get('isoapp')
comments = REQUEST.form.get('comments')
date = REQUEST.form.get('date')

filename=id
filename = filename.split('\\')[-1]

# call it, passing arguments
insert( department=department, title=title, filename=filename,
version=version, url=url, ownerapp=ownerapp, isoapp=isoapp,
comments=comments, date=date)

# return a confirmation page
page=container['thanks.html']
return page()


writeDB()
*

On 11/15/05, Mike Jakowlew <mjakowlew at gmail.com> wrote:
>
> Here's what I'm trying to accomplish:
>
> 1. The user fills out a form page with various fields
> 2. The user selects a file to upload
> 3. when the user hits submit two things should happen:
> - The file selected is uploaded
> - all the filled out form fields are written to the database (MS SQL)
>
> This is my current problem:
> The writting to the database part works fine on it's own, but when
> combined with the file upload I get this error
>
> *Error Type: AttributeError*
> *Error Value: 'NoneType' object has no attribute 'headers'*
>
>
> My code:
>
> *********HTML FORM**********
> <html>
> <h1 tal:content="template/title">title</h1>
> <p>Fill out the form below to update the website with the appropriate
> info:</p>
>
> <form action="uploadForm.py">
> <table width="100%" border="0" cellspacing="0" cellpadding="0">
> <tr>
> <td width="16%" height="27" align="right"><strong>Your Dept:
> </strong></td>
> <td width="84%"><input type="text" name="department"></td>
> </tr>
> <tr>
> <td height="27" align="right"><strong>Document Title:</strong></td>
> <td><input type="text" name="title"></td>
> </tr>
> <tr>
> <td height="30" align="right"><strong>Filename:</strong></td>
> <td><input type="file" name="upload_filename" ></td>
> </tr>
> <tr>
> <td height="28" align="right"><strong>Version of File :</strong></td>
> <td><input type="text" name="version"></td>
> </tr>
> <tr>
> <td height="28" align="right"><strong>URL:</strong></td>
> <td><input type="text" name="url"></td>
> </tr>
> <tr>
> <td height="33" align="right"><strong>Owner Approved:</strong></td>
> <td><input type="text" name="ownerapp"></td>
> </tr>
> <tr>
> <td align="right"><strong>ISO Approved:</strong></td>
> <td><input type="text" name="isoapp"></td>
> </tr>
> <tr>
> <td height="41" align="right"><strong>Comments: </strong></td>
> <td rowspan="2"><textarea name="comments" cols="60" rows="5">
> </textarea></td>
> </tr>
> <tr>
> <td height="85" align="right" valign="top">&nbsp;</td>
> </tr>
> <tr>
> <td height="29" align="right"><strong>Date</strong></td>
> <td><input type="text" name="date"></td>
> </tr>
> <tr>
> <td height="62" align="right"></td>
> <td><p>
> <input type="submit" id="submit" name="submit" />
>
> </p>
> </td>
> </tr>
> </table>
> <p>
>
> </form>
> <hr>
> <p>Return to the <a href="NewsTable">News page</a></p>
> </html>
>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://mail.zope.org/pipermail/zope/attachments/20051115/e5e45ea1/attachment.htm


More information about the Zope mailing list