0
votes

How do I access just the MIME ext part of UIImagePickerControllerReferenceURL? This is what I get when I NSLog -(void)imagePickerController:(UIImagePickerController *)picker didFinishPickingMediaWithInfo:(NSDictionary *)info

UIImagePickerControllerReferenceURL = "assets-library://asset/asset.PNG?id=F61B754A-705C-4BFB-9965-DE34C7B93A2B&ext=PNG";

I just want access to the MIME type. When I send an image to my webserver using:

NSData *imageData = UIImageJPEGRepresentation(_selectedImage, 1.0);

//non-important ASIFormDataRequest set-up
[request setData:imageData withFileName:uniqueString andContentType:@"image/jpeg" forKey:@"photo"];

The picture comes in all messed up. But when I use :

NSData *imageData = UIImagePNGRepresentation(_selectedImage);

//non-important ASIFormDataRequest set-up
[request setData:imageData withFileName:uniqueString andContentType:@"image/png" forKey:@"photo"];

The picture comes in fine. But all my uploaded photos won't be PNG though.

3

3 Answers

1
votes

Dimitris's answer on this thread worked like a charm. I am going to keep typing now so this doesn't get relegated to a trivial answer, and then automatically made into a comment.

1
votes

To get image extension in swift :

 func imagePickerController(picker: UIImagePickerController, didFinishPickingMediaWithInfo info: [String : AnyObject]) {
            if let pickedImage = info[UIImagePickerControllerOriginalImage] as? UIImage {
                let assetPath = info[UIImagePickerControllerReferenceURL] as! NSURL
                let ext = assetPath.absoluteString.componentsSeparatedByString("ext=")[1]
                 print(ext)
        }
    }
0
votes

Please try below code to extract extension from UIImagePickerControllerReferenceURL

NSURL *referenceURL = @"assets-library://asset/asset.PNG?id=F61B754A-705C-4BFB-9965-DE34C7B93A2B&ext=PNG"; //put your reference URL here
NSString *fileExtension = [referenceURL.absoluteString componentsSeparatedByString:@"ext="][1];