[Zope] File Upload via python

Matthew T. Kromer matt@zope.com
Thu, 21 Feb 2002 16:01:27 -0500


Jonathan Bryant wrote:

> [...]


>
> <table>
>     <form method="post" action="testAction" 
> enctype="multi-part/form-data">
>     <tr><td><strong>FileTitle</strong></td><td><input type="text" 
> name="item_title" maxlength="30"></td></tr>
>     <tr><td><strong>Select File</strong></td><td><input type="file" 
> name="item"></td></tr>
>        <tr><td align=center colspan=2><input type="submit" Value="Add 
> File"></td></tr>
>     </form>
> </table>
>
> [...]
>
> My question is, how do I get the filename or headers? I'm guessing 
> that when I reference 'item' I'm getting a FileUpload object. What 
> confuses me is that I can't reference item.filename or 
> item.headers['Content-Type']. I've also tried using 
> REQUEST['item'].filename like I've seen in several examples. What am I 
> doing wrong here?
>
> Thanks in advance,
>


One thing you want to do is change the name of the file item from "item" 
to "item:file".   This tells the publisher that the data is a file item. 
 You should then be able to access its headers.  Note that it's still 
really called "item" in your code, the ":file" is a hint to the 
publisher about how to marshall your input data.

-- 
Matt Kromer
Zope Corporation  http://www.zope.com/