How would you determine the mime type for an NSData object? I plan to have the user to upload a video/picture from their iPhone and have that file be wrapped in a NSData class.
I was wondering if I can tell the mime type from the NSData. There are only a few answers to this question and the most recent one is from 2010 (4 years ago!). Thanks!
NSData *data; // can be an image or video
NSString *mimeType = [data getMimetype]; // how would I implement getMimeType
Best Answer
Based on ml's answer from a similar post, I've added the mime types determination for NSData:
ObjC:
Swift:
This handle main file types only, but you can complete it to fit your needs: all the files signature are available here, just use the same pattern as I did.
PS: all the corresponding mime types are available here