hi, how do i upload a file in Zope using a python script?? regards, varun __________________________________________________ Do You Yahoo!? Tired of spam? Yahoo! Mail has the best spam protection around http://mail.yahoo.com
how do i upload a file in Zope using a python script??
http://www.zopelabs.com/cookbook/1006887320 is probably a place to start.
Brian Sullivan wrote:
how do i upload a file in Zope using a python script??
http://www.zopelabs.com/cookbook/1006887320
is probably a place to start.
On that topic: I've got my file upload working properly (it forwards the file data to an external site, then saves only if validation works). But I just started to wonder about something; all my tests have been with relatively small files (~40KB) but my end users may be uploading some very large files (possibly as large as 500KB, although not for months). In my python script I use: filedata = container.REQUEST.file.read() then merge this data into a MIME submission for the external web site, and on success, save it locally as a "file". My question is -- aside from memory usage, what problems might there be with this approach? Will the "read()" return all the content, or is there a possibility that it will return less than the full file contents? Any timeout issues that I should consider? I can test with large files, but can't really emulate internet network latencies. Thanks, Nikko
Am Freitag, den 03.06.2005, 11:09 -0600 schrieb Nikko Wolf:
Brian Sullivan wrote:
how do i upload a file in Zope using a python script??
http://www.zopelabs.com/cookbook/1006887320
is probably a place to start.
On that topic: I've got my file upload working properly (it forwards the file data to an external site, then saves only if validation works).
But I just started to wonder about something; all my tests have been with relatively small files (~40KB) but my end users may be uploading some very large files (possibly as large as 500KB, although not for months).
In my python script I use: filedata = container.REQUEST.file.read() then merge this data into a MIME submission for the external web site, and on success, save it locally as a "file".
My question is -- aside from memory usage, what problems might there be with this approach?
Will the "read()" return all the content, or is there a possibility that it will return less than the full file contents? Any timeout issues that I should consider?
Of course does read() return all the data in one string - the python documentation leaves no doubt here. You might consider reading in chunks, encoding them while you send and if validation is successfull, rewind by file.seek(0) and then manage_addFile() directly with the file object. Timeout can be an issue with large files and when the remote server is slow. In this case, you can send some data to the clients browser while you work, via context.REQUEST.RESPONSE.write() Note: once you start using response.write() you cannot use return() in your script - at least the user wont see any output from it. You also should catch exeptions and provide meaningfull output when they happen since the usual exeption handling will work but the user wont see its output.
Hi Tino. I was reading this and I was looking at incorporating some kind of response to users while processing a time consuming script. I was thinking about just putting up an animated gif that says 'Processing' (or something similar or to send some text advising where they are in the processing). I am trying to understand what you are saying about the return. If at the end of the process you did something like a return or redirect will this not work properly? Is there a script example that you can point me to that demonstrates a context.REQUEST.RESPONSE.write() admidst processing somewhere to provide feedback while processing. Many thanks. Regards, David On Friday, June 3, 2005, at 03:24 PM, Tino Wildenhain wrote:
Timeout can be an issue with large files and when the remote server is slow. In this case, you can send some data to the clients browser while you work, via context.REQUEST.RESPONSE.write()
Note: once you start using response.write() you cannot use return() in your script - at least the user wont see any output from it. You also should catch exeptions and provide meaningfull output when they happen since the usual exeption handling will work but the user wont see its output.
On 3 Jun 2005, at 18:09, Nikko Wolf wrote:
In my python script I use: filedata = container.REQUEST.file.read() then merge this data into a MIME submission for the external web site, and on success, save it locally as a "file".
My question is -- aside from memory usage, what problems might there be with this approach?
It is *highly dangerous* to start requests to external resources from a running Zope request, unless you make sure the external request has a timeout that kicks in if it hangs for any reason. Just four hanging external resource requests and your Zope site is dead because all available threads are in use... jens
participants (6)
-
Brian Sullivan -
David Pratt -
Jens Vagelpohl -
Nikko Wolf -
Tino Wildenhain -
Varun Parange