Become a MacRumors Supporter for $50/year with no ads, ability to filter front page stories, and private forums.

sspbond007

macrumors member
Original poster
Aug 19, 2008
46
0
Hi!!!,

I have written an iphone application that requires to upload an image (.png) into the server. But, I do not know how to upload this image data into the server. I found a thread post regarding the upload of image data into the server but actually I do not know how it actually works. Please see this code:

-(void)searchAction:(UIImage*)theImage
{

UIDevice *dev = UIDevice currentDevice;
NSString *uniqueId = dev.uniqueIdentifier;

UIImage *testImage = UIImage imageNamed:mad:"image1.png";

NSData * imageData = UIImagePNGRepresentation(testImage);

NSString *postLength = [NSString stringWithFormat:mad:"%d", imageData length];

NSString *urlString = @"http://example.com/rtl?" stringByAppendingString:mad:"ve=iPhoneV0&mcid";
urlString = [urlString stringByAppendingString:uniqueId];
urlString = urlString stringByAppendingString:mad:"&lang=en_US.UTF-8";

NSMutableURLRequest *request = [[NSMutableURLRequest alloc] init] autorelease;
[request setURL:NSURL URLWithString:urlString];
request setHTTPMethod:mad:"POST";
request setValue:postLength forHTTPHeaderField:mad:"Content-Length";
request setHTTPBody:imageData;

NSURLConnection *conn=[NSURLConnection alloc] initWithRequest:request delegate:self;
if (conn)
{
receivedData = [NSMutableData data] retain;
}

If this code is working then please tell me how to extract data on the server side so that I can insert image data into a database.

Thanks with warm regards.
 
Register on MacRumors! This sidebar will go away, and you'll see fewer ads.