<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<HTML><HEAD>
<META http-equiv=Content-Type content="text/html; charset=iso-8859-1">
<META content="MSHTML 6.00.2900.2769" name=GENERATOR>
<STYLE></STYLE>
</HEAD>
<BODY bgColor=#ffffff>
<DIV><FONT face=Arial size=2>You should use the getContentType() method - look 
in the zope book (API - File).</FONT></DIV>
<DIV><FONT face=Arial size=2></FONT>&nbsp;</DIV>
<DIV><FONT face=Arial size=2>Jonathan</FONT></DIV>
<BLOCKQUOTE 
style="PADDING-RIGHT: 0px; PADDING-LEFT: 5px; MARGIN-LEFT: 5px; BORDER-LEFT: #000000 2px solid; MARGIN-RIGHT: 0px">
  <DIV style="FONT: 10pt arial">----- Original Message ----- </DIV>
  <DIV 
  style="BACKGROUND: #e4e4e4; FONT: 10pt arial; font-color: black"><B>From:</B> 
  <A title=mjakowlew@gmail.com href="mailto:mjakowlew@gmail.com">Mike 
  Jakowlew</A> </DIV>
  <DIV style="FONT: 10pt arial"><B>To:</B> <A title=zope@zope.org 
  href="mailto:zope@zope.org">zope@zope.org</A> </DIV>
  <DIV style="FONT: 10pt arial"><B>Sent:</B> Tuesday, November 15, 2005 9:25 
  AM</DIV>
  <DIV style="FONT: 10pt arial"><B>Subject:</B> [Zope] Problems using forms to 
  upload files to Zope</DIV>
  <DIV><BR></DIV>Here's what I'm trying to accomplish:<BR><BR>1. The user fills 
  out a form page with various fields<BR>2. The user selects a file to 
  upload<BR>3. when the user hits submit two things should 
  happen:<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; - The file selected is uploaded 
  <BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; - all the filled out form fields are 
  written to the database (MS SQL)<BR><BR>This is my current problem:<BR>The 
  writting to the database part works fine on it's own, but when combined with 
  the file upload I get this error <BR><BR><STRONG 
  style="FONT-WEIGHT: normal">Error Type: AttributeError</STRONG><BR><STRONG 
  style="FONT-WEIGHT: normal">Error Value: 'NoneType' object has no attribute 
  'headers'</STRONG><BR><BR><BR>My code:<BR><BR>*********HTML 
  FORM**********<BR>&lt;html&gt;<BR>&lt;h1 
  tal:content="template/title"&gt;title&lt;/h1&gt; <BR>&lt;p&gt;Fill out the 
  form below to update the website with the appropriate 
  info:&lt;/p&gt;<BR><BR>&lt;form action="uploadForm.py"&gt;<BR>&lt;table 
  width="100%"&nbsp; border="0" cellspacing="0" cellpadding="0"&gt; <BR>&nbsp; 
  &lt;tr&gt;<BR>&nbsp;&nbsp;&nbsp; &lt;td width="16%" height="27" 
  align="right"&gt;&lt;strong&gt;Your Dept: 
  &lt;/strong&gt;&lt;/td&gt;<BR>&nbsp;&nbsp;&nbsp; &lt;td 
  width="84%"&gt;&lt;input type="text" name="department"&gt;&lt;/td&gt; 
  <BR>&nbsp; &lt;/tr&gt;<BR>&nbsp; &lt;tr&gt;<BR>&nbsp;&nbsp;&nbsp; &lt;td 
  height="27" align="right"&gt;&lt;strong&gt;Document 
  Title:&lt;/strong&gt;&lt;/td&gt;<BR>&nbsp;&nbsp;&nbsp; &lt;td&gt;&lt;input 
  type="text" name="title"&gt;&lt;/td&gt; <BR>&nbsp; &lt;/tr&gt;<BR>&nbsp; 
  &lt;tr&gt;<BR>&nbsp;&nbsp;&nbsp; &lt;td height="30" 
  align="right"&gt;&lt;strong&gt;Filename:&lt;/strong&gt;&lt;/td&gt;<BR>&nbsp;&nbsp;&nbsp; 
  &lt;td&gt;&lt;input type="file" name="upload_filename" &gt;&lt;/td&gt; 
  <BR>&nbsp; &lt;/tr&gt;<BR>&nbsp; &lt;tr&gt;<BR>&nbsp;&nbsp;&nbsp; &lt;td 
  height="28" align="right"&gt;&lt;strong&gt;Version of File 
  :&lt;/strong&gt;&lt;/td&gt;<BR>&nbsp;&nbsp;&nbsp; &lt;td&gt;&lt;input 
  type="text" name="version"&gt;&lt;/td&gt; <BR>&nbsp; &lt;/tr&gt;<BR>&nbsp; 
  &lt;tr&gt;<BR>&nbsp;&nbsp;&nbsp; &lt;td height="28" 
  align="right"&gt;&lt;strong&gt;URL:&lt;/strong&gt;&lt;/td&gt;<BR>&nbsp;&nbsp;&nbsp; 
  &lt;td&gt;&lt;input type="text" name="url"&gt;&lt;/td&gt; <BR>&nbsp; 
  &lt;/tr&gt;<BR>&nbsp; &lt;tr&gt;<BR>&nbsp;&nbsp;&nbsp; &lt;td height="33" 
  align="right"&gt;&lt;strong&gt;Owner 
  Approved:&lt;/strong&gt;&lt;/td&gt;<BR>&nbsp;&nbsp;&nbsp; &lt;td&gt;&lt;input 
  type="text" name="ownerapp"&gt;&lt;/td&gt; <BR>&nbsp; &lt;/tr&gt;<BR>&nbsp; 
  &lt;tr&gt;<BR>&nbsp;&nbsp;&nbsp; &lt;td align="right"&gt;&lt;strong&gt;ISO 
  Approved:&lt;/strong&gt;&lt;/td&gt;<BR>&nbsp;&nbsp;&nbsp; &lt;td&gt;&lt;input 
  type="text" name="isoapp"&gt;&lt;/td&gt;<BR>&nbsp; &lt;/tr&gt; <BR>&nbsp; 
  &lt;tr&gt;<BR>&nbsp;&nbsp;&nbsp; &lt;td height="41" 
  align="right"&gt;&lt;strong&gt;Comments: 
  &lt;/strong&gt;&lt;/td&gt;<BR>&nbsp;&nbsp;&nbsp; &lt;td 
  rowspan="2"&gt;&lt;textarea name="comments" cols="60" rows="5"&gt; 
  <BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 
  &lt;/textarea&gt;&lt;/td&gt;<BR>&nbsp; &lt;/tr&gt;<BR>&nbsp; 
  &lt;tr&gt;<BR>&nbsp;&nbsp;&nbsp; &lt;td height="85" align="right" 
  valign="top"&gt;&amp;nbsp;&lt;/td&gt;<BR>&nbsp;&nbsp;&nbsp; 
  &lt;/tr&gt;<BR>&nbsp; &lt;tr&gt;<BR>&nbsp;&nbsp;&nbsp; &lt;td height="29" 
  align="right"&gt;&lt;strong&gt;Date&lt;/strong&gt;&lt;/td&gt;<BR>&nbsp;&nbsp;&nbsp; 
  &lt;td&gt;&lt;input type="text" name="date"&gt;&lt;/td&gt;<BR>&nbsp; 
  &lt;/tr&gt;<BR>&nbsp; &lt;tr&gt; <BR>&nbsp;&nbsp;&nbsp; &lt;td height="62" 
  align="right"&gt;&lt;/td&gt;<BR>&nbsp;&nbsp;&nbsp; 
  &lt;td&gt;&lt;p&gt;<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &lt;input type="submit" 
  id="submit" name="submit" /&gt;<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 
  <BR>&nbsp;&nbsp;&nbsp; &lt;/p&gt; <BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 
  &lt;/td&gt;<BR>&nbsp; 
  &lt;/tr&gt;<BR>&lt;/table&gt;<BR>&lt;p&gt;<BR><BR>&lt;/form&gt;<BR>&lt;hr&gt;<BR>&lt;p&gt;Return 
  to the &lt;a href="NewsTable"&gt;News 
  page&lt;/a&gt;&lt;/p&gt;<BR>&lt;/html&gt;<BR><BR>******uploadForm.py********<BR><BR>def 
  writeDB():<BR>&nbsp;&nbsp;&nbsp; # get sql method<BR>&nbsp;&nbsp;&nbsp; 
  insert=container['insert_fileapps']<BR><BR>&nbsp;&nbsp;&nbsp; 
  REQUEST=context.REQUEST<BR>&nbsp;&nbsp;&nbsp; <BR>&nbsp;&nbsp;&nbsp; 
  department = REQUEST.form.get('department')<BR>&nbsp;&nbsp;&nbsp; title = 
  REQUEST.form.get('title')<BR>&nbsp;&nbsp;&nbsp; filename = 
  REQUEST.form.get('upload_filename')<BR><BR>&nbsp;&nbsp;&nbsp; 
  content_type=filename.headers['Content-Type']<BR>&nbsp;&nbsp;&nbsp; if 
  content_type.find('image')!=-1:<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 
  context.manage_addImage(id, file, title) <BR>&nbsp;&nbsp;&nbsp; 
  else:<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; context.manage_addFile(id, 
  file, title)<BR>&nbsp;&nbsp;&nbsp; return 'Finished'<BR><BR>&nbsp;&nbsp;&nbsp; 
  version = REQUEST.form.get('version')<BR>&nbsp;&nbsp;&nbsp; url = 
  REQUEST.form.get('url')<BR>&nbsp;&nbsp;&nbsp; ownerapp = 
  REQUEST.form.get('ownerapp') <BR>&nbsp;&nbsp;&nbsp; isoapp = 
  REQUEST.form.get('isoapp')<BR>&nbsp;&nbsp;&nbsp; comments = 
  REQUEST.form.get('comments')<BR>&nbsp;&nbsp;&nbsp; date = 
  REQUEST.form.get('date')<BR><BR>&nbsp;&nbsp;&nbsp; 
  filename=id<BR>&nbsp;&nbsp;&nbsp; filename = 
  filename.split('\\')[-1]<BR><BR>&nbsp;&nbsp;&nbsp; # call it, passing 
  arguments <BR>&nbsp;&nbsp;&nbsp; insert( department=department, title=title, 
  filename=filename, version=version, url=url, ownerapp=ownerapp, isoapp=isoapp, 
  comments=comments, date=date)<BR><BR>&nbsp;&nbsp;&nbsp; # return a 
  confirmation page<BR>&nbsp;&nbsp;&nbsp; page=container[' 
  thanks.html']<BR>&nbsp;&nbsp;&nbsp; return 
  page()<BR><BR><BR>writeDB()<BR><BR>************************<BR><BR>Any help 
  provided would be greatly appreciated<BR>Thanks in 
  advance,<BR>mjakowlew<BR><BR>************************<BR>PS: I'm sorry if I 
  went about posting this in the wrong spot or the wrong way, I'm new to this 
  <BR>
  <P>
  <HR>

  <P></P>_______________________________________________<BR>Zope maillist&nbsp; 
  -&nbsp; 
  Zope@zope.org<BR>http://mail.zope.org/mailman/listinfo/zope<BR>**&nbsp;&nbsp; 
  No cross posts or HTML encoding!&nbsp; **<BR>(Related lists - 
  <BR>&nbsp;http://mail.zope.org/mailman/listinfo/zope-announce<BR>&nbsp;http://mail.zope.org/mailman/listinfo/zope-dev 
  )<BR></BLOCKQUOTE></BODY></HTML>