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. _______________________________________________ Zope maillist - Zope@zope.org http://mail.zope.org/mailman/listinfo/zope ** No cross posts or HTML encoding! ** (Related lists - http://mail.zope.org/mailman/listinfo/zope-announce http://mail.zope.org/mailman/listinfo/zope-dev )