[Zope-dev] [Zope] Header information on file upload

Florent Guillaume fg@nuxeo.com
Sat, 1 Feb 2003 19:26:29 +0000 (UTC)


Martin Gebert  <Murphy@members.netsolution-net.de> wrote:
> In my HowTo about dealing with BLOBs 
> <http://www.zope.org/Members/murphy/MySQL-BLOBs> I use a rather 
> unelegant but working method to get the content type of an uploaded 
> file. Stefan Tjarks has now drawn my attention to the Header attributes 
> of the uploaded form data, namely the "Content-Type" attribute which 
> seems to reveal the MIME type (photo.headers['Content-Type'] for the 
> given exsample).
> My sorrow is now that this information isn't 100 % reliable, 'cause the 
> Zope core (esp. the Image and File classes) doesn't seem to use this 
> possibility either, but implements it's own methods which I use in the 
> HowTo, too. The responsible class ZPublisher.HTTPRequest.FileUpload 
> seems only to reach through the header information from the browser. 
> Also I've learned through SelfHTML that the MIME type support of 
> browsers has holes sometimes, as described for the accept attribute of 
> the <form> tag.
> Does anybody have further information on that issue, and why 
> headers['Content-Type'] isn't used by Zope (it is, in fact, but in 
> ZPublisher for seemingly other purposes)?

The File and Image objects use the Content-Type header on upload if it
is provided by the browser. Only if none is provided does it guess one.
See OFS.Image.File._get_content_type().

Florent
-- 
Florent Guillaume, Nuxeo (Paris, France)
+33 1 40 33 79 87  http://nuxeo.com  mailto:fg@nuxeo.com