0

I've a problem with uploading a Microsoft Office 2007 document using AspUpload (used to implement the upload form at my website):

If I upload a PowerPoint document with FF3.6 I get a ContentType value "application/x-itunes-itlp".

When using IE8 I get, as expected, ContentType value "application/vnd.openxmlformats-officedocument.presentationml.presentation".

Is this a problem of the used component or a Firefox problem? Does anybody know about this?

UPDATE: Where it's working for Word 2007 documents: both FF and IE gives "application/vnd.openxmlformats-officedocument.wordprocessingml.document"

waanders
  • 8,907
  • 22
  • 70
  • 102

1 Answers1

0

You simply cannot trust the value of "ContentType" sent by a browser to be correct. See section 4.5 of RFC-2388 to see what the spec says about content-type.

If you require robust file type detection you will need to use byte-sniffing techniques to accurately determine the real content type. This is commonly referred to as reading the magic number of a file. This technique allows you to identify the format of a file independently of additional information supplied by the user.

There are many existing projects that encapsulate this task including TrID and Apache Tiki.

Uriah Carpenter
  • 6,656
  • 32
  • 28
  • Thanks. "you will need to use byte-sniffing techniques". Such as? – waanders Mar 30 '11 at 18:52
  • @waanders Similar [question asked](http://stackoverflow.com/questions/4839125/a-solution-to-validate-a-file-type-using-magic-number-in-file-signature-net) about sniffing file types in .NET. (Also updated answer.) – Uriah Carpenter Mar 30 '11 at 19:24
  • I did some experiments and found out that the problem in my case is the browser + OS settings. I've tried uploading at 2 different computers with both FF3.6.16 (exactly the same UA), 1 gives "application/x-itunes-itlp", the other one "application/vnd.openxmlformats-officedocument.presentationml.presentation". Thanks for your help, what I've learned is NOT to rely on the ContentType sent by the browser – waanders Mar 31 '11 at 10:22