Raja Subramanian wrote:
Hi,
Johan Carlsson wrote:
Johan Carlsson wrote at 2004-9-3 08:55 +0200:
For Images you can use
from Globals import ImageFile
file=ImageFile('www/image.gif', globals())
Despite its name, you can use "ImageFile" for arbitrary files and not only for images.
Provide it actually can guess the content_type.
I'm running zope 2.6.4, python 2.2.3 on debian sarge.
file = ImageFile('www/applet.jar', globals())
produced the following http headers -
Content-Type: application/x-java-archive
For PDF files, it produced "application/pdf" and for MS Word documents it produces "application/msword". ImageFile is pretty clever :-)
Yes. It looks it uses from OFS.content_types import guess_content_type which in turn uses Python mime_types module which defines 120 or so mimetype2ext mappings. I'm just one of those guys who prefers explicit from implicit :-)
I would subclass ImageFile and override the __init__ with an extra content_type argument. But that's me :-)
I found that on debian I can make ImageFile understand new content types simply by modifying /etc/mime.types.
Yeah, mimetypes seems to look for mime types in: "/etc/mime.types", "/usr/local/etc/httpd/conf/mime.types", "/usr/local/lib/netscape/mime.types", "/usr/local/etc/httpd/conf/mime.types", # Apache 1.2 "/usr/local/etc/mime.types", # Apache 1.3 and there's also a mime.types in OFS. Even though, in a Product I would rather not require the user to configure mime.types just to install my prodct :-) -- Johan Carlsson Tel: + 46 8 31 24 94 Colliberty Mob: + 46 70 558 25 24 Torsgatan 72 Email: johanc@easypublisher.com SE-113 37 STOCKHOLM