Any way to guess the mime type on Delphi XE2?

前端 未结 4 860
爱一瞬间的悲伤
爱一瞬间的悲伤 2021-02-08 13:09

I need to guess the mime type with the purpose of fill the \"Content-Type\" header for some file uploads.

I fail to found a solution for it.

I wish to call somet

4条回答
  •  长情又很酷
    2021-02-08 13:18

    How many file types are you talking about? Maybe you can just create a list of types you want to support.

    I can imagine these lists to be available on the internet as well, for instance

    • here: http://www.webmaster-toolkit.com/mime-types.shtml
    • here: http://webdesign.about.com/od/multimedia/a/mime-types-by-file-extension.htm
    • here: List of ALL MimeTypes on the Planet, mapped to File Extensions?
    • here: http://hul.harvard.edu/ois/systems/wax/wax-public-help/mimetypes.htm

    Just get the file extension using ExtractFileExt and check it agains one of those lists. A file doesn't have a mime type in it, so you'll need to use either this list of file extensions, or determine the type by reading the file headers, which is harder and just as unreliable.

提交回复
热议问题