upload file to a server ios -


hey guyz m trying upload image server using code parameters

1) file ($_files array)

2) name (timestamp_random.jpg)

3) userid" "{ ""error_code"": ""000"", ""message"": ""file uploaded"" }"

output:

"{    ""error_code"": ""000"",    ""message"": ""file uploaded""}" 

but giving error have no idea why

please

  // setting request object  nsurl *nsurl =[nsurl urlwithstring:@"http://www.webdevelopersrus.com/php/salman_m/meetingapp/api/photoupload"]; nsmutableurlrequest *request = [nsmutableurlrequest requestwithurl:nsurl cachepolicy:nsurlrequestuseprotocolcachepolicy timeoutinterval:60.0]; [request seturl:nsurl]; [request sethttpmethod:@"post"];   nsstring *boundary = @"---------------------------14737809831466499882746641449"; nsstring *contenttype = [nsstring stringwithformat:@"multipart/form-data; boundary=%@",boundary]; [request addvalue:contenttype forhttpheaderfield: @"content-type"];  /*  lets create body of post  */ nsmutabledata *body = [nsmutabledata data];  nsstring *parameter1 = @"name"; nsstring *tag = @"file"; nsstring *status = @"userid";   [body appenddata:[[nsstring stringwithformat:@"\r\n--%@\r\n",boundary] datausingencoding:nsutf8stringencoding]]; [body appenddata:[[nsstring stringwithformat:@"content-disposition: form-data; name=\"parameter1\"\r\n\r\n%@", parameter1] datausingencoding:nsutf8stringencoding]]; [body appenddata:[[nsstring stringwithformat:@"\r\n--%@\r\n",boundary] datausingencoding:nsutf8stringencoding]];   [body appenddata:[[nsstring stringwithformat:@"content-disposition: form-data; name=\"tag\"\r\n\r\n%@", tag] datausingencoding:nsutf8stringencoding]]; [body appenddata:[[nsstring stringwithformat:@"\r\n--%@\r\n",boundary] datausingencoding:nsutf8stringencoding]];   [body appenddata:[[nsstring stringwithformat:@"content-disposition: form-data; name=\"status\"\r\n\r\n%@", status] datausingencoding:nsutf8stringencoding]]; [body appenddata:[[nsstring stringwithformat:@"\r\n--%@\r\n",boundary] datausingencoding:nsutf8stringencoding]];   nsdata *data = uiimagejpegrepresentation(imgv.image, 1.0f);  [body appenddata:[nsdata datawithdata:data]]; [body appenddata:[[nsstring stringwithformat:@"\r\n--%@--\r\n",boundary] datausingencoding:nsutf8stringencoding]];  // setting body of post reqeust [request sethttpbody:body];  nsdata *returndata = [nsurlconnection sendsynchronousrequest:request returningresponse:nil error:nil];  nsstring* newstr = [[nsstring alloc] initwithdata:returndata                                          encoding:nsutf8stringencoding];  nslog(@"%@",newstr); 


Comments

Popular posts from this blog

monitor web browser programmatically in Android? -

Shrink a YouTube video to responsive width -

wpf - PdfWriter.GetInstance throws System.NullReferenceException -