I have learned two method(Probably there is more..) to upload image on server..
1) Create NSData and add it into request body
2) Create Byte Array and send it in json like simple array
1) Create NSData and add it into request body
Create NSData from the image using this code
NSData *imageData = UIImagePNGRepresentation(myimage);
And than add it in request body
NSMutableURLRequest *request = [[[NSMutableURLRequest alloc] init] autorelease];
[request setURL:[NSURL URLWithString:urlString]];
[request setHTTPMethod:@"POST"];
[body appendData:[NSData dataWithData:imageData]];
[request setHTTPBody:body];
Perform request and Image will be uploaded on server.
2) Create Byte Array and send it in json like simple array
Create Byte array of image
NSData *imageData = UIImagePNGRepresentation(myimage);
const unsigned char *bytes = [imageData bytes];
NSUInteger length = [imageData length];
NSMutableArray *byteArray = [NSMutableArray array];
for (NSUInteger i = 0; i<length; i++)
{
[byteArray addObject:[NSNumber numberWithUnsignedChar:bytes[i]]];
}
And than send it in request using JSON like any other array
But which is the better solution or there is another faster way..