0

I am creating iPhone app where I am taking photo. Now I want to save this photo online (say at link www.test.com/myiPhoneAppImages/).

Any idea how to take image from iPhone to website?

I tried googling it, however didn't find any useful tuts.

Any help/ suggestion would be greatful.

Fahim Parkar
  • 30,974
  • 45
  • 160
  • 276

3 Answers3

4

Oh! don't know why google won't give you any result, let I did it for you!

1) Uploading images to Remote Server, iPhone

2) upload images and texts to server

3) how to upload UIImage on server?

4) Iphone> Uploading UIImage object to server via ASIHTTPRequest, photo name?

5) iphone: upload image to server using ASIFormDataRequest ---Recommanded

Overall Results page

Community
  • 1
  • 1
Hemang
  • 26,840
  • 19
  • 119
  • 186
0

Try the below method to post images to server

- (void) doPostImage

{
    NSAutoreleasePool   *pool                       = [[NSAutoreleasePool alloc]init];

    //Add your images here...
    NSArray *imageParams = [NSArray arrayWithObjects:@"myimage1.png", nil];



    NSString *urlString = @"http://yourURL";

    NSMutableURLRequest *request = [[NSMutableURLRequest alloc] init];

    [request setURL:[NSURL URLWithString:urlString]];

    [request setHTTPMethod:@"POST"];



    NSMutableData *body = [NSMutableData data];



    NSString *boundary = @"---------------------------14737809831466499882746641449";

    NSString *contentType = [NSString stringWithFormat:@"multipart/form-data; boundary=%@", boundary];

    [request addValue:contentType forHTTPHeaderField:@"Content-Type"];


    // add the image form fields

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

        [body appendData:[[NSString stringWithFormat:@"--%@\r\n", boundary] dataUsingEncoding:NSUTF8StringEncoding]];

        [body appendData:[[NSString stringWithFormat:@"Content-Disposition: attachment; name=\"image%d\"; filename=\"%@\"\r\n", i, [imageParams objectAtIndex:i]] dataUsingEncoding:NSUTF8StringEncoding]];

        [body appendData:[@"Content-Type: application/octet-stream\r\n\r\n" dataUsingEncoding:NSUTF8StringEncoding]];

        [body appendData:[NSData dataWithData:UIImageJPEGRepresentation(m_ImgVw_SelectedImage.image, 90)]];

        [body appendData:[@"\r\n" dataUsingEncoding:NSUTF8StringEncoding]];

    }

    // add the text form fields


    // close the form
        [body appendData:[[NSString stringWithFormat:@"--%@--\r\n", boundary] dataUsingEncoding:NSUTF8StringEncoding]];

    // set request body
       [request setHTTPBody:body];



    // send the request (submit the form) and get the response

    NSData *returnData = [NSURLConnection sendSynchronousRequest:request returningResponse:nil error:nil];
    [request release];

    NSString *returnString = [[NSString alloc] initWithData:returnData encoding:NSUTF8StringEncoding];



    if(returnString)
    {
        [m_ctrlActivityView stopAnimating];
        NSString *m_strMessage=[NSString stringWithFormat:@" Your image is recieved"];
        [returnString release];
        UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"Thank you" message:m_strMessage delegate:self cancelButtonTitle:@"OK" otherButtonTitles:nil];
        [alert show];
        [alert release];
    }
    else
    {
        UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"Sorry" message:@"Error in server communication. Try again later" delegate:self cancelButtonTitle:@"OK" otherButtonTitles:nil];
        [alert show];
        [alert release];

    }


    CFRunLoopRun();


    [pool release];
}
Vishnu
  • 208
  • 5
  • 19
0

you could search it in the search engine.

data way: phone image-----upload to website------save to dataBase by the website logic.

By the way,you needn't to write the upload logic yourself, AFNetworking would be a cool third-part framework for you. GitHub link

junkor
  • 373
  • 1
  • 11