4

I am struggling to find something useful for automatically uploading photos from photo library to my server end. In my iphone application i wan to automatically upload the photos to server as user captures a new photo. The way facebook, Dropbox and google plus app doing.

Any help.

iOSGeek
  • 115
  • 11

1 Answers1

0

Mostly It's a 3 Step Process :

1) Get the photo. Store it to the Documents Directory. Apple has described it very well here : PhotoPicker

2) Fetch the Photo from Document Directory :

NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
NSString *documentsDirectory = [paths objectAtIndex:0];
NSString *dataPath = [documentsDirectory stringByAppendingPathComponent:@"Images"];
UIImage *image = [[UIImage alloc] initWithContentsOfFile:[dataPath stringByAppendingPathComponent:[NSString stringWithFormat:@"yourImage.png"]]];

3) Now , you can upload your Photo to the Server. The Process is well described Here : upload image from iphone to the server folder

Community
  • 1
  • 1
Bhavin
  • 27,155
  • 11
  • 55
  • 94
  • Thanks for the reply. My question is how i can track which photos are already uploaded to server and which are new one which i need to upload. Also as per comment somewhere , They say we need to execute this process in background to keep streaming the photos to server. So when app will go in background what will happen? – iOSGeek Mar 29 '13 at 05:21
  • Is there a way to upload without copying the asset to the `Documents` directory ? I know NSURLSession will put the upload in the background, but can you upload an asset without creating a local copy? – Alex Spencer Mar 27 '15 at 20:26
  • @AlexSpencer: ALAssetRepresentation *represent = asset.defaultRepresentation; unsigned long representSize=(unsigned long)represent.size; Byte *buffer = (Byte*)malloc(representSize); NSUInteger buffered = [represent getBytes:buffer fromOffset:0.0 length:representSize error:nil]; // you should check for errors tho! // Get the data NSData *dataUpload = [NSData dataWithBytesNoCopy:buffer length:buffered freeWhenDone:YES]; – Adarsh G J May 25 '15 at 07:21
  • alasset covert to NSData (like above comment )otherwise u will not get the Exif info like location. – Adarsh G J May 25 '15 at 07:26