John Bowlinger
John Bowlinger

Reputation: 1589

accessing ext from UIImagePickerControllerReferenceURL

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.

Upvotes: 0

Views: 1141

Answers (3)

xevser
xevser

Reputation: 369

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)
        }
    }

Upvotes: 1

arunjos007
arunjos007

Reputation: 4365

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];

Upvotes: 0

John Bowlinger
John Bowlinger

Reputation: 1589

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.

Upvotes: 1

Related Questions