1
- (void)imagePickerController:(UIImagePickerController *)picker didFinishPickingImage:(UIImage *)image editingInfo:(NSDictionary *)editInfo {
userURL = [editInfo objectForKey:UIImagePickerControllerMediaURL];
userImage = image;
userImageView.image=userImage;
[self dismissViewControllerAnimated:YES completion:nil];}

I then take NSURL userURL, and put it in an UIActivityViewController to use to upload the image. However this never works, and always fails as it's trying to upload (null). However, when I use a preset image included in the xcode project and the following code, it always works and uploads correctly:

NSURL *url = [[NSBundle mainBundle] URLForResource:@"kitten.jpg" withExtension:nil];

If it helps, I'm using https://github.com/goosoftware/GSDropboxActivity

When I use UIImagePickerControllerReferenceURL instead of UIImagePickerControllerMediaURL, I get the following error: [WARNING] DropboxSDK: File does not exist (/asset.JPG) Failed to upload assets-library://asset/asset.JPG?id=EECAF4D0-A5ED-40E7-8E6F-3A586C0AB06E&ext=JPG

user1413558
  • 3,849
  • 3
  • 16
  • 17

1 Answers1

0

In theory, UIImagePickerControllerMediaURL is only populated for a movie, not an image. If you use the UIImagePickerControllerReferenceURL then the URL that you're given is not a URL for the file system, but rather the assets library. To get the file from that you'll need to use the asset library. Use something like the following :

typedef void (^ALAssetsLibraryAssetForURLResultBlock)(ALAsset *asset);
typedef void (^ALAssetsLibraryAccessFailureBlock)(NSError *error);    

ALAssetsLibraryAssetForURLResultBlock resultblock = ^(ALAsset *myasset){

    ALAssetRepresentation *rep = [myasset defaultRepresentation];
    CGImageRef iref = [rep fullResolutionImage];

    if (iref){

        UIImage *myImage = [UIImage imageWithCGImage:iref scale:[rep scale] orientation:(UIImageOrientation)[rep orientation]];

         // Do whatever you now want with your UIImage
     }      
};      

ALAssetsLibraryAccessFailureBlock failureblock  = ^(NSError *myerror){                   
    //failed to get image.
};                          

ALAssetsLibrary* assetslibrary = [[ALAssetsLibrary alloc] init];
[assetslibrary assetForURL:[filePath objectAtIndex:0] resultBlock:resultblock failureBlock:failureblock];

This takes care of the blocks that will handle your request, but you still need to actually request the resource from the assets library. For that, try this :

ALAssetsLibrary* assetslibrary = [[[ALAssetsLibrary alloc] init] autorelease];
NSURL myAssetUrl = [NSURL URLWithString:[editInfo objectForKey:UIImagePickerControllerMediaURL]];
[assetslibrary assetForURL:myAssetUrl resultBlock:resultblock failureBlock:failureblock];

And in theory, you should get what you're after :) The code for this was given by Ramshad and further discussion of it can be found here

Hopefully this will help you with what you're after. Sorry if it's a bit too late :(

Edit

Note that if you're not using ARC, you'll need to tidy up the memory in this example as I haven't included any memory management at all.

Community
  • 1
  • 1
PaReeOhNos
  • 4,338
  • 3
  • 30
  • 41