Re: [Zope] Stupid File Upload Question
On Fri, Dec 15, 2000 at 04:59:07PM -0800, Jonothan Farr wrote: What sort of problems were you seeing with LocalFS? Maybe I can fix them. Thanks, --jfarr - Original Message - From: [EMAIL PROTECTED] To: [EMAIL PROTECTED] Sent: Friday, December 15, 2000 4:22 PM Subject: [Zope] Stupid File Upload Question This is for Jos: I ran into the same problem today. I had previously used this method, and it works better than LocalFS for my purposes. Anyway, be absolutly sure that your form says: Fiest, LocalFS turns out to have the same problem. MSIE does not interact well with method=get and file input methods. form method=post action=whatever method="multipart/form-data" ... /form Then you should be able to access REQUEST.form['attachment'].filename and REQUEST.form['attachment'].read() (Well, I hope). If the method=post is omitted, Netscape (linux at least) will work. MSIE will not. Man I ain't got enough hair for these kinds of problems! Jim Penny I want/need to collect some metadata along with the file. Say I want a file, a title, some keywords. (And I have some idiots with 80MB files). I would like to enforce the following: No two files from a given user can have the same title. A given file may not be uploaded twice by the same user with different titles. With LocalFS, as it stands, it is hard to determine the file that was uploaded. (It is not returned by manage_upload, I could create an id, but that has its own problems (downloading creates unexpected files on the client PC's)). This can be modified, but... More importantly, it is really hard to see how to handle both of the conditios above cleanly. With LocalFS, I found no easy way at all to combine the error checking implied by the metadata and the error checking desired for the file name. ___ 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 )
Re: [Zope] Stupid File Upload Question
On Fri, Dec 15, 2000 at 07:22:43PM -0500, [EMAIL PROTECTED] wrote: Anyway, be absolutly sure that your form says: form method=post action=whatever method="multipart/form-data" Of course, that should be ENCTYPE instead of the second METHOD attribute name: form method=post action=whatever enctype="multipart/form-data" As an aside, I found the following page to be a useful example of Zope file-upload handling: http://classic.zope.org/pipermail/zope/1999-July/006591.html -- Fred Yankowski [EMAIL PROTECTED] tel: +1.630.879.1312 Principal Consultant www.OntoSys.com fax: +1.630.879.1370 OntoSys, Inc 38W242 Deerpath Rd, Batavia, IL 60510, USA ___ 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
This is for Jos: I ran into the same problem today. I had previously used this method, and it works better than LocalFS for my purposes. Anyway, be absolutly sure that your form says: form method=post action=whatever method="multipart/form-data" ... /form Then you should be able to access REQUEST.form['attachment'].filename and REQUEST.form['attachment'].read() (Well, I hope). If the method=post is omitted, Netscape (linux at least) will work. MSIE will not. Man I ain't got enough hair for these kinds of problems! Jim Penny ___ 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
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
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? 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 )