Hi all,

ZODB.blob.Blob.consumeFile() needs a real, existing filesystem location
passed into it to work, which is why plone.app.blob[1] patches
ZPublisher.HTTPRequest.FieldStorage to generate a
tempfile.NamedTemporaryFile() instead of a tempfile.TemporaryFile() for
large uploaded files.

However, if one tries to consume a NamedTemporaryFile and then open its
generated blob before closing the tempfile, Windows complains:

>>>> import ZODB.blob, tempfile
>>>> f = tempfile.NamedTemporaryFile()
>>>> b = ZODB.blob.Blob()
>>>> b.consumeFile(f.name)
>>>> b.open('r')
> Traceback (innermost last):
> ...
> IOError: [Errno 13] Permission denied: 'c:\\buildout\\var\\tmp\\tmpsuykkc'

Closing the NamedTemporaryFile after consuming it and before opening the
blob makes the matters worse, since Windows removes the file from under Blob
*after* it has been consumed, so we'll have to think of a different strategy
for consuming request files on Windows, but whichever strategy ends up being
used, the problem remains that we cannot keep the FileUpload instance from
the request open in 'w+' mode (readable and writable) while allowing the
blob instance to be opened in the same request. So I'd like to ask some
policy questions:

1. Is it ok to close a FileUpload instance from the request?

2. Alternatively, is it ok to replace it on the request with a read-only
file-like object with the same contents, or maybe even force it to be
read-only to begin with?

If none of the above are ok, then we'll be forced to copy the whole file on
Windows when consuming an uploaded file from the request into a blob, unless
we use some non-portable win32 code to allow writing and reading to the same
file simultaneously.

[1] http://dev.plone.org/plone/browser/plone.app.blob

View this message in context: 
Sent from the Zope - Dev mailing list archive at Nabble.com.

Zope-Dev maillist  -  Zope-Dev@zope.org
**  No cross posts or HTML encoding!  **
(Related lists - 
 http://mail.zope.org/mailman/listinfo/zope )

Reply via email to