Hello, I have been looking at the FileUpload class defined in HTTPRequest.py but am still a little confused about how it works. When a form is submitted with an <input type="file" ...>, where are the contents of the uploaded file stored? Is it automatically stored in the ZODB, or is it stored in memory until some other code (like that in Image.py) stores it? The reason I am asking is that I want to store uploaded files on the file system instead of in the ZODB. (We are running Zope behind an Apache web server, so the uploaded files will be placed under Apache's document root so they can be served directly by Apache.) Being new to Zope and Python, it is not clear to me exactly how to go about this. Any suggestions would be appreciated, or if somebody knows where there is some sample code and could point me to it, that would be great too. Thanks, --Toby. --------------------------- Toby Gustafson Senior Software Engineer Tyrell Software Corporation Email: tobyg@tyrell.com ---------------------------
Toby Gustafson wrote:
When a form is submitted with an <input type="file" ...>, where are the contents of the uploaded file stored? Is it automatically stored in the ZODB, or is it stored in memory until some other code (like that in Image.py) stores it?
Its stored in a temporary file as defined by the tempfile module. -- Jamie Heilman http://audible.transient.net/~jamie/ "We must be born with an intuition of mortality. Before we know the words for it, before we know there are words, out we come bloodied and squalling with the knowledge that for all the compasses in the world, there's only one direction, and time is its only measure." -Rosencrantz
I have been looking at the FileUpload class defined in HTTPRequest.py but am still a little confused about how it works.
When a form is submitted with an <input type="file" ...>, where are the contents of the uploaded file stored? Is it automatically stored in the ZODB, or is it stored in memory until some other code (like that in Image.py) stores it?
The reason I am asking is that I want to store uploaded files on the file system instead of in the ZODB. (We are running Zope behind an Apache web server, so the uploaded files will be placed under Apache's document root so they can be served directly by Apache.) Being new to Zope and Python, it is not clear to me exactly how to go about this.
Don't bother mucking around in the core. The right way to do it is to use a Product that stores data on the fiesystem, acting as a facade. Look at LocalFS, ExtFile/ExtImage, ExternalFile, and possibly APE. Probably LocalFS or ExternalFile are most interesting to you. http://sourceforge.net/projects/localfs http://zope.org/Members/arielpartners/ExternalFile http://zope.org/Members/MacGregor/ExtFile http://hathaway.freezope.org/Software/Ape --jcc
Its handy enough to implement. lets say your file parameter is called 'file'... #os_uploadCacheImage is a Zope External method. if request.has_key('file'): context.os_uploadCacheImage(context.PATH_CACHE, request['file'], request['file'].filename) #co-responding implementation for zope external method os_uploadCacheImage def uploadCacheImage(self, basePath, file, filename): cacheFile = open(basePath + "/" + filename, "wb") cacheFile.write(file.read()) cacheFile.close() --- J Cameron Cooper <jccooper@jcameroncooper.com> wrote:
I have been looking at the FileUpload class defined
in HTTPRequest.py
but am still a little confused about how it works.
When a form is submitted with an <input type="file" ...>, where are the contents of the uploaded file stored? Is it automatically stored in the ZODB, or is it stored in memory until some other code (like that in Image.py) stores it?
The reason I am asking is that I want to store uploaded files on the file system instead of in the ZODB. (We are running Zope behind an Apache web server, so the uploaded files will be placed under Apache's document root so they can be served directly by Apache.) Being new to Zope and Python, it is not clear to me exactly how to go about this.
Don't bother mucking around in the core. The right way to do it is to use a Product that stores data on the fiesystem, acting as a facade.
Look at LocalFS, ExtFile/ExtImage, ExternalFile, and possibly APE. Probably LocalFS or ExternalFile are most interesting to you.
http://sourceforge.net/projects/localfs http://zope.org/Members/arielpartners/ExternalFile http://zope.org/Members/MacGregor/ExtFile http://hathaway.freezope.org/Software/Ape
--jcc
_______________________________________________ Zope-Dev maillist - Zope-Dev@zope.org http://mail.zope.org/mailman/listinfo/zope-dev ** No cross posts or HTML encoding! ** (Related lists - http://mail.zope.org/mailman/listinfo/zope-announce http://mail.zope.org/mailman/listinfo/zope )
participants (4)
-
Declan Shanaghy -
J Cameron Cooper -
Jamie Heilman -
Toby Gustafson