Hi all, I've been playing around with Zope for several days and really like it. I'm amazed at how simple so many things that take alot of effort in php, asp etc. are amazingly simple in Zope. One of those things is file upload, which works but still puzzles me. I have a form in a dtml method that looks like this: <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> I figured out that using a python script I can add the file just by referencing it's name from the form, which is incredibly cool: context.manage_addProduct['OFSP'].manage_addFile('newFile', item_title, item) What I'd like to do is easily grab the filename: context.manage_addProduct['OFSP'].manage_addFile(item.filename, item_title, item) 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, Jonathan Bryant jonathanbryant@hotmail.com _________________________________________________________________ MSN Photos is the easiest way to share and print your photos: http://photos.msn.com/support/worldwide.aspx
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/
Jonathan Bryant writes:
I've been playing around with Zope for several days and really like it. I'm amazed at how simple so many things that take alot of effort in php, asp etc. are amazingly simple in Zope. One of those things is file upload,... .... What I'd like to do is easily grab the filename:
context.manage_addProduct['OFSP'].manage_addFile(item.filename, item_title, item) This should work as you write it here.
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. Right!
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. All of these should work!
The access to "headers" may throw an "Unauthorized" exception because in former Zope versions, a security declaration was missing (not sure about the current version). What happens for you: an "Unauthorized" exception, an "AttributeError", or what? We always want good problem descriptions. Such descriptions contain "Error Type", "Error Value" and usually (at least) the last part of the resulting traceback! Dieter
participants (3)
-
Dieter Maurer -
Jonathan Bryant -
Matthew T. Kromer