1

I am trying to access iPhone's photo album photo images through ALAssetsLibrary and upload(send) the images to my server. I am being successful accessing the photo album and get the asset URL of each images, via the following code:

    - (void)viewDidLoad
{
    [super viewDidLoad];


    void (^assetEnumerator)(struct ALAsset *, NSUInteger, BOOL *) = ^(ALAsset *result, NSUInteger index, BOOL *stop) {
        if(result != NULL) {
            NSLog(@"See Asset: %@", result);
            [assets addObject:result];
            // Here storing the asset's image URL's in NSMutable array urlStoreArr
            NSURL *url = [[result defaultRepresentation] url];
            [urlStoreArr addObject:url]; 
        }
    };

    void (^assetGroupEnumerator)(struct ALAssetsGroup *, BOOL *) =  ^(ALAssetsGroup *group, BOOL *stop) 
    {

        if(group != nil) {
            [group enumerateAssetsUsingBlock:assetEnumerator];
        }
        [self.activity stopAnimating];
        [self.activity setHidden:YES];
    };
    assets = [[NSMutableArray alloc] init];
    library = [[ALAssetsLibrary alloc] init];
    [library enumerateGroupsWithTypes:ALAssetsGroupAlbum
                           usingBlock:assetGroupEnumerator
                         failureBlock: ^(NSError *error) {
                             NSLog(@"Failure");
                         }];

    urlStoreArr = [[NSMutableArray alloc] init];
}

    -(void) UploadImagesToServer
{

for (int i=0; i<[urlStoreArr count]; i++)

{

       // To get the each image URL here...

        NSString *str = [urlStoreArr objectAtIndex:i];
        NSLog(@"str: %@",str);

        // Need to upload the images to my server..

    }


}

I want to upload the images which i got from the device asset's URL to my server. Could someone please advise how can i program it for sending the images to the server using this case?

Thank you!

Getsy
  • 4,887
  • 16
  • 78
  • 139

1 Answers1

0

you could use the below SO post code for uploading images to server.

How can I upload a photo to a server with the iPhone?

upload image from iphone to the server folder

Community
  • 1
  • 1
Jhaliya - Praveen Sharma
  • 31,697
  • 9
  • 72
  • 76
  • Thanks a lot Jhaliya! The second link helps lot. I would have an additional question as well, what if i want to upload the video files which got from ALAsset URL path? – Getsy Mar 26 '11 at 14:35
  • Glad to hear it help u: You need to follow the same process except your NSData will hold video data instead of image... – Jhaliya - Praveen Sharma Mar 26 '11 at 14:43
  • Unfortunately i'm not able to get image URL's using ALAssetsLibrary code mentioned in my actual query on iOS 4.1 device, don't know why? It works as expected on iOS 4.0 simulator well. If anyone has idea why doesn't it work on physical device, please suggest me what can i do ? – Getsy Mar 28 '11 at 16:19
  • Try turning on location services on your device. – crgt Aug 03 '11 at 09:19