将ALAsset URL映像上载到服务器

时间:2011-03-26 13:38:19

标签: iphone objective-c alasset

我正在尝试通过ALAssetsLibrary访问iPhone的相册照片图像,并将图像上传(发送)到我的服务器。我正在通过以下代码成功访问相册并获取每张图片的资产URL:

    - (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..

    }


}

我想将从设备资产的URL上获取的图像上传到我的服务器。有人可以告诉我如何使用这种情况编程将图像发送到服务器?

谢谢!

1 个答案:

答案 0 :(得分:0)

您可以使用以下SO邮政编码将图片上传到服务器。

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

upload image from iphone to the server folder