I am trying to upload image, but in the post request I need to pass "Content-Type" i.e the mime type of the image which I have picked from iOS Photo library, but when I am trying to get the mime type it is coming nil.
Here is the process :-
Note: imgProfileURL is of type NSString
- (void)imagePickerController:(UIImagePickerController *)picker didFinishPickingMediaWithInfo:(NSDictionary *)info
{
imgProfileURL=[NSString stringWithFormat:@"%@",[info objectForKey:@"UIImagePickerControllerReferenceURL"]];
}
imgProfileURL now contains:-
assets-library://asset/asset.JPG?id=B6C0A21C-07C3-493D-8B44-3BA4C9981C25&ext=JPG
Now, I am calling the below function to get MIME type and passing the value of imgProfileURL
- (NSString *)mimeTypeForPath:(NSString *)path
{
// get a mime type for an extension using MobileCoreServices.framework
CFStringRef extension = (__bridge CFStringRef)[path pathExtension];
CFStringRef UTI = UTTypeCreatePreferredIdentifierForTag(kUTTagClassFilenameExtension, extension, NULL);
assert(UTI != NULL);
NSString *mimetype = CFBridgingRelease(UTTypeCopyPreferredTagWithClass(UTI, kUTTagClassMIMEType)); //it is NULL
assert(mimetype != NULL); // Crashing here
CFRelease(UTI);
return mimetype;
}
mimetype
is coming NULL here.
I have gone through this question , but didn't help me:- LINK