Re: [Zope] stupid file upload question
Thanks for the responses. My first message was a little unclear... Here is what I am doing in more detail: On the client side (me), I have a windows machine, and I am uploading a file: "E:\test\my_file" On the server, I am running Zope on Linux. My upload form looks like this: dtml-var standard_html_header h2dtml-var title_or_id/h2 p form method="post" action="Customize" enctype="multipart/form-data" input type="file" name="attached_file" input type=submit /form /p dtml-var standard_html_footer So I use this form, and I think the file gets uploaded, though I'm not quite sure where it goes. The "Customize" DTML gets called when the form is submitted, it looks like this: dtml-var standard_html_header h2dtml-var title_or_id dtml-var document_title/h2 p filename: dtml-var "get_file_name(REQUEST)" /p dtml-var standard_html_footer And the "get_file_name" is a Python External Method, which looks like this: def get_file_name(self,REQUEST): s = REQUEST.form['attached_file'].filename return s Everything works great so far. Now I want to do something with that file I just uploaded. What is its name on the server? The "filename" in the field I am pretty sure is NOT the name of the file on the local system, since when I look at it, it says "E:\test\myfile" and this is on a Linux system, so there is no such path. That is the name file had on my Windows system. What sort of object is this "REQUEST.form['attached_file']"? Is there some way to find out this sort of thing when you have a Python object? (I'm new to Python) Is that even the place to look to get the name of the file on the server after it is uploaded? That's why I mentioned the quote from that How-To (which the above is basically a copy of): "In you python external method you can now reference REQUEST.form['attached_file'] as a normal file. You can perform things such as read() on the object. " This makes it seem like whatever is necessary, it is very easy, but there's some detail that I am missing. Maybe I just don't know what a "normal file" is... Regards, JJ Dieter Maurer wrote: Joh Johannsen writes: But it says: "In you python external method you can now reference REQUEST.form['attached_file'] as a normal file. You can perform things such as read() on the object. " Now in my Python external method, I can reference things like: REQUEST.form['attached_file'].filename and that is fine. But what is the syntax for actually reading the file? From the above quote I thought it was as simple as x=REQUEST.form['attached_file'].read() but that doesn't work... Please tell us, how it does not work (in fact, it should work): Did you get an attribute error (read) or was the result wrong? You must use the 'enctype="multipart/form-data"' and 'method=post' form parameter to upload files. Did you do that? Dieter ___ Zope maillist - [EMAIL PROTECTED] http://lists.zope.org/mailman/listinfo/zope ** No cross posts or HTML encoding! ** (Related lists - http://lists.zope.org/mailman/listinfo/zope-announce http://lists.zope.org/mailman/listinfo/zope-dev )
Re: [Zope] stupid file upload question
Dieter Maurer wrote: Joh Johannsen writes: What sort of object is this "REQUEST.form['attached_file']"? Is there some way to find out this sort of thing when you have a Python object? (I'm new to Python) It is a "ZPublisher.HTTPRequest.FileUpload" object. From its (source) documentation: File upload objects are used to represent file-uploaded data. File upload objects can be used just like files. In addition, they have a 'headers' attribute that is a dictionary containing the file-upload headers, and a 'filename' attribute containing the name of the uploaded file. Is that even the place to look to get the name of the file on the server after it is uploaded? You should not rely on the fact that the data is stored somewhere on the server. That's why I mentioned the quote from that How-To (which the above is basically a copy of): "In you python external method you can now reference REQUEST.form['attached_file'] as a normal file. You can perform things such as read() on the object. " "REQUEST.form['attached_file']" should be a "FileUpload" object and as such have a "read" method (beside many others). Thus, "REQUEST.form['attached_file'].read()" should return the file content. In an earlier message, you said, it did not. What happened? What happens is that if I have this: def get_file_name(self,REQUEST): s = REQUEST.form['attached_file'].filename contents = REQUEST.form['attached_file'].read() return s I get a Zope error for the External Method, when I reload it by clicking on "edit" Here is traceback... Traceback (innermost last): File /usr/local/Zope-2.2.0-src/lib/python/ZPublisher/Publish.py, line 222, in publish_module File /usr/local/Zope-2.2.0-src/lib/python/ZPublisher/Publish.py, line 187, in publish File /usr/local/Zope-2.2.0-src/lib/python/Zope/__init__.py, line 221, in zpublisher_exception_hook (Object: get_file_name) File /usr/local/Zope-2.2.0-src/lib/python/ZPublisher/Publish.py, line 171, in publish File /usr/local/Zope-2.2.0-src/lib/python/ZPublisher/mapply.py, line 160, in mapply (Object: manage_edit) File /usr/local/Zope-2.2.0-src/lib/python/ZPublisher/Publish.py, line 112, in call_object (Object: manage_edit) File /usr/local/Zope-2.2.0-src/lib/python/Products/ExternalMethod/ExternalMethod.py, line 201, in manage_edit (Object: get_file_name) File /usr/local/Zope-2.2.0-src/lib/python/Products/ExternalMethod/ExternalMethod.py, line 210, in getFunction (Object: get_file_name) File /usr/local/Zope-2.2.0-src/lib/python/App/Extensions.py, line 217, in getObject (Info: ('/usr/local/Zope2/Extensions/get_file_name.py', 'get_file_name')) SyntaxError: (see above) JJ ___ Zope maillist - [EMAIL PROTECTED] http://lists.zope.org/mailman/listinfo/zope ** No cross posts or HTML encoding! ** (Related lists - http://lists.zope.org/mailman/listinfo/zope-announce http://lists.zope.org/mailman/listinfo/zope-dev )
[Zope] stupid file upload question
OK, there is a How-To on that, which is helpful, by benno But it says: "In you python external method you can now reference REQUEST.form['attached_file'] as a normal file. You can perform things such as read() on the object. " Now in my Python external method, I can reference things like: REQUEST.form['attached_file'].filename and that is fine. But what is the syntax for actually reading the file? From the above quote I thought it was as simple as x=REQUEST.form['attached_file'].read() but that doesn't work... Either that or some way to get at the name of the file on the server. The above 'filename' is just giving me the name of the file on the client side, I have no idea where it is on the server. Thanks, JJ ___ Zope maillist - [EMAIL PROTECTED] http://lists.zope.org/mailman/listinfo/zope ** No cross posts or HTML encoding! ** (Related lists - http://lists.zope.org/mailman/listinfo/zope-announce http://lists.zope.org/mailman/listinfo/zope-dev )
Re: [Zope] Help! publishing Images from a Database
This works with mysql: 1. make mysql table with a LONGBLOB field for holding the image, suppose you make it a field called "imageData" 2. in your DTML, do this (assume getImage gets the image you want) dtml-in getImage dtml-call "RESPONSE.setHeader('content-type','image/png')" dtml-return imageData /dtml-in The retrieve, etc. things you mentioned are just sql, displaying it is the tricky part! Regards, JJ Mohan Baro wrote: Can anyone help me to I want to know how I can publish images stored in a SQL database. I am trying to create an online photo album that stores images in a database. The features I want to implement are: RetrieveImage, UpdateImage, InsertImage I am running zope on linux mandrake and use ZSever The database I am currently using is MySQL on MySQLDA (MySQLdb non-binary dist.) Mo. ___ Zope maillist - [EMAIL PROTECTED] http://lists.zope.org/mailman/listinfo/zope ** No cross posts or HTML encoding! ** (Related lists - http://lists.zope.org/mailman/listinfo/zope-announce http://lists.zope.org/mailman/listinfo/zope-dev ) ___ Zope maillist - [EMAIL PROTECTED] http://lists.zope.org/mailman/listinfo/zope ** No cross posts or HTML encoding! ** (Related lists - http://lists.zope.org/mailman/listinfo/zope-announce http://lists.zope.org/mailman/listinfo/zope-dev )