[Zope] File types and OpenOffice documents (text)

J Cameron Cooper jccooper at jcameroncooper.com
Fri Aug 29 18:56:21 EDT 2003


>When uploading an OpenOffice text document ("foo.sxw") to a File object
>("foo.sxw"), it's content type prop is set to "application/x-zip-compressed"
>!!!
>
>When downloading it with IE or Mozilla (Windows) it renames the file
>"foo.sxw.zip". The user has to rename it :-(.
>
>Is there a way to set the correct content type automatically at upload time
>(dunno which) and prevent renaming the file ?
>
>* Upload through Python scripts that detects those strnga behaviours and set
>the content type according to the file extension ?
>
>* Add a plugin to the File class to check the right type and set content
>type accordingly ?
>
>* Other ?
>  
>
In the File class, in zope/lib/python/OFS/Image.py, the content-type is 
set by the supplied 'content-type' header or by 
content_types.guess_content_type, which uses the Python mimetypes 
library (plus a bit of extra logic for circumstances the library doesn't 
deal with).

My guess is that you are not providing a type and that the mimetypes 
library's guess_type function is looking at the contents of your OO file 
to guess the type. Since they are, I think, zipped XML files, it's not a 
bad guess.

Your first fix would work, though it's a bit messy. Better would be to 
fix it in either the Zope core or the Python library. Zope is easy 
enough: you can add your file extension to the '_addtypes' tuple in 
zope/lib/python/OFS/content_types.py directly, or if you want to be less 
invasive you can do a monkeypatch/hotfix. Then submit the change to the 
collector for inclusion in future versions, at which point you can 
discard your site-specific fix. The fix to Python will require going to 
the maintainer, perhaps with a patch. I can't say what the policy on 
changes to that library is.

          --jcc

-- 
"My point and period will be throughly wrought,
Or well or ill, as this day's battle's fought."





More information about the Zope mailing list