create new tag
, view all tags

Feature Proposal: Preserve Content-Type from HTTP form upload in attachment


When HTTP transfers files, a MIME header always accompanies the file. This includes files uploaded in forms in addition to documents downloaded from a web server. One of the important pieces of information in the MIME header is the Content-Type, or the type of the file. Currently when attaching a file to a topic, TWiki does essentially this:

  • Receive the file from the browser
  • Discard the type information included with the file and save the file

And then when someone gets the file it attempts to guess what the type of the file was based on a suffix of the name. This is silly. Why not just preserve the filetype originally included with the file when it was uploaded?


When an attachment is uploaded to a topic, the Content Type is retreived and saved along with the file. When using a web server such as Apache, using this feature, the original filetype is returned to the user and there is no need to guess it.

When showing a list of attachments, which icon to display to the left of the file is determined from its filetype instead of being guessed from its name.

When editing an attachment, the filetype can be changed.

-- PhillipVandry - 22 Feb 2005

Impact and Available Solutions


The role of the _filetypes.txt file must change; it becomes a mapping from filetype to image instead of a mapping from name patterns to image.

If the web server does not support CERN style metafiles as mentioned above, the behaviour will revert to the web server guessing the type of the file based on the suffix of its name. This is no different than what happens without this patch.

I also created a topic PreserveFileTypes before I noticed that that is the old workflow. I expect this topic should replace it?

yes. I deleted the old topic. Though for future reference, you could have just changed the form. Look for "replace form" in light gray text beside the form name while in edit mode. It doesn't look like a link but it is. -- MattWilkie - 23 Feb 2005




Added Phillip's name to the contributor field as he supplied the code to fulfill his feature request. Thanks Phillip!

-- MattWilkie - 23 Feb 2005

Topic attachments
I Attachment History Action Size Date Who Comment
Unknown file formatpatch twiki.preserve-filetype.patch r1 manage 10.9 K 2005-02-22 - 19:38 PhillipVandry Patch against TWiki20040902
Edit | Attach | Watch | Print version | History: r2 < r1 | Backlinks | Raw View | Raw edit | More topic actions
Topic revision: r2 - 2005-02-23 - MattWilkie
  • Learn about TWiki  
  • Download TWiki
This site is powered by the TWiki collaboration platform Powered by Perl Hosted by OICcam.com Ideas, requests, problems regarding TWiki? Send feedback. Ask community in the support forum.
Copyright © 1999-2018 by the contributing authors. All material on this collaboration platform is the property of the contributing authors.