0

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.

John Bowlinger
  • 1,561
  • 4
  • 12
  • 14

3 Answers3

1

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.

Community
  • 1
  • 1
John Bowlinger
  • 1,561
  • 4
  • 12
  • 14
1

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)
        }
    }
xevser
  • 369
  • 4
  • 5
0

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];
arunjos007
  • 4,105
  • 1
  • 28
  • 43