I don't know why getContentType() doesn't exist
anymore?! a quick 'dir' of a file instance attributes
yields:
['close', 'filename', 'fileno', 'flush', 'headers',
'isatty', 'read', 'readinto', 'readline', 'readlines', 'seek', 'tell',
'truncate', 'write', 'writelines', 'xreadlines']
Anybody out there know what happened to
'getContentType'?
However, there is always a work around:
REQUEST['fname'].headers['Content-Type']
should get you what you want.
Jonathan
----- Original Message -----
Sent: Tuesday, November 15, 2005 1:19
PM
Subject: [Zope] Re: Problems using forms
to upload files to Zope
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@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"> </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>
_______________________________________________
Zope maillist
-
Zope@zope.org
http://mail.zope.org/mailman/listinfo/zope
**
No cross posts or HTML encoding! **
(Related lists -
http://mail.zope.org/mailman/listinfo/zope-announce
http://mail.zope.org/mailman/listinfo/zope-dev
)