How can you read a files MIME-type in objective-c

后端 未结 9 1628
伪装坚强ぢ
伪装坚强ぢ 2020-12-01 01:50

I am interested in detecting the MIME-type for a file in the documents directory of my iPhone application. A search through the docs did not provide any answers.

9条回答
  •  一整个雨季
    2020-12-01 02:55

    I'm not sure what are the practices on iPhone, but if you're allowed to, I'd make use of UNIX philosophy here: use program file, which is the standard way to detect filetype on an UNIX operating system. It includes a vast database of magic markers for filetype detection. Since file is probably not shipped on iPhone, you could include it in your app bundle. There might be a library implementing file's functionality.

    Alternatively, you could trust the browser. Browsers send the MIME type they guessed somewhere in the HTTP headers. I know that I can easily grab the MIME type information in PHP. That of course depends if you're willing to trust the client.

提交回复
热议问题