How to upload image to remote server in iphone?

I am trying to upload an image that I click with a camera. I am trying to execute the following code to upload an image to a remote server.

-(void)searchAction:(UIImage*)theImage { UIDevice *dev = [UIDevice currentDevice]; NSString *uniqueId = dev.uniqueIdentifier; NSData * imageData = UIImagePNGRepresentation(theImage); NSString *postLength = [NSString stringWithFormat:@"%d",[imageData length]]; NSString *urlString = [@"http://www.amolconsultants.com/im.jsp?" stringByAppendingString:@"imagedata=iPhoneV0&mcid="]; urlString = [urlString stringByAppendingString:uniqueId]; urlString = [urlString stringByAppendingString:@"&lang=en_US.UTF-8"]; NSMutableURLRequest *request = [[[NSMutableURLRequest alloc] init] autorelease]; [request setURL:[NSURL URLWithString:urlString]]; [request setHTTPMethod:@"POST"]; [request setValue:postLength forHTTPHeaderField:@"Content-Length"]; [request setHTTPBody:imageData]; NSURLConnection *conn=[[NSURLConnection alloc] initWithRequest:request delegate:self]; if (conn == nil) { NSLog(@"Failed to create the connection"); } } 

But nothing is published. Nothing comes to the console window either. I call this method in the action sheet. When the user clicks on the first button of the action sheet, this method is called to publish the image.

Can anyone help me with this ...

Any code would be very helpful ...

Thanx in advance ...

+4
source share
1 answer

You can use libraries from a third party called asi-http-request . It’s just for you most of the hard work. In your case, you simply follow these steps:

 ASIHTTPRequest *request = [ASIHTTPRequest requestWithURL:url]; [request appendPostData:imageData]; [request setRequestMethod:@"PUT"]; 
+3
source

Source: https://habr.com/ru/post/1303830/


All Articles