I download some files, such as word, ppt, excel. But i don't know their MIMETYPE and suffix. Is there some way can get MIMETYPE of these file?
Asked
Active
Viewed 786 times
0
-
Have you try any code ? – Yatendra Aug 04 '17 at 06:38
-
3possible duplicate of https://stackoverflow.com/questions/1363813/how-can-you-read-a-files-mime-type-in-objective-c – Yatendra Aug 04 '17 at 06:41
-
6Possible duplicate of [How can you read a files MIME-type in objective-c](https://stackoverflow.com/questions/1363813/how-can-you-read-a-files-mime-type-in-objective-c) – Toni Vanhala Aug 04 '17 at 06:45
-
But I don't know their suffix,these way can't work. – coderL Aug 04 '17 at 07:03
-
Content-Type is zip,but they are Microsoft Office File. – coderL Aug 07 '17 at 01:36
1 Answers
1
If you don't know the suffix, you're forced to look at the file contents. Typically this starts with looking for magic bytes, the first few bytes of the file. You can often qualify the type of file on that basis (though you obviously can't be sure unless you validate the whole file).
For modern Office documents, they should conform to OOXML and the first two bytes should be 0x50 0x4b (i.e. "PK") the indicator of a zip file.
You can then uncompress it (e.g. with ZipArchive).
You can then either parse the docProps/app.xml or see Office Open XML site with links at the top of the page for how to parse word processing, excel, and presentations, respectively.

Rob
- 415,655
- 72
- 787
- 1,044