tags:

views:

69

answers:

1

I am trying to upload an image to server using iphone . I haven't done it before.

But I am not getting how can i do it.

I know how to add text data on server.

But how to add the image data or an Image to server . Can any one suggest!?

+1  A: 

Try this .

http://stackoverflow.com/questions/1166549/how-to-upload-an-image-in-iphone-application

and this

http://stackoverflow.com/questions/125306/how-can-i-upload-a-photo-to-a-server-with-the-iphone

EDIT:

NSMutableURLRequest *urlRequest =
    [NSMutableURLRequest requestWithURL:url];
    [urlRequest setHTTPMethod:@"POST"];
    [urlRequest setValue:
     [NSString stringWithFormat:@"multipart/form-data; boundary=%@", boundry]
      forHTTPHeaderField:@"Content-Type"];

    NSMutableData *postData =
    [NSMutableData dataWithCapacity:[data length] + 512];
    [postData appendData:
     [[NSString stringWithFormat:@"--%@\r\n", boundry] dataUsingEncoding:NSUTF8StringEncoding]];
    [postData appendData:
     [[NSString stringWithFormat:
       @"Content-Disposition: form-data; name=\"%@\"; filename=\"file.bin\"\r\n\r\n", FORM_FLE_INPUT]
      dataUsingEncoding:NSUTF8StringEncoding]];
    [postData appendData:data];
    [postData appendData:
     [[NSString stringWithFormat:@"\r\n--%@--\r\n", boundry] dataUsingEncoding:NSUTF8StringEncoding]];

    [urlRequest setHTTPBody:postData];

Also check out the video : http://www.youtube.com/watch?v=aQXaJO36I7Y

The kid is explaining the things pretty easily .you can do the thing with that video .

You will also need a php script to parse the image at server side .

hib
Its not working... no code is dere.