ios - How to upload image,audio,databaseid,caption in server in iphone -


i new phone programming.using below code uploading caption, user_id, mobile_tauky_id, blauky_id, image, audio in server not uploading,its taking long after not displaying think in console.

 uiimage * img = [uiimage imagenamed:@"elephant.jpg"];     nsdata *imagedata = uiimagejpegrepresentation(img,0.2);              nsstring *file2 = [[nsbundle mainbundle] pathforresource:@"ch" oftype:@"mp3"];         nsdata *audiodata = [nsdata datawithcontentsoffile:file2];         nsstring* captionn = [nsstring stringwithformat:@"aslam"];         nsstring* user_idd = [nsstring stringwithformat:@"1"];         nsstring* mobile_tauky_idd = [nsstring stringwithformat:@"2"];         nsstring* blauky_idd = [nsstring stringwithformat:@"0"];         nsstring *urlstring = @" http://182.73.152.59:82/php/tauky_services/codeigniter-restserver-master/index.php/api/uploadclass/uploadtauky/";          //[request seturl:[nsurl urlwithstring:@" http://182.73.152.59:82/php/tauky_services/codeigniter-restserver-master/index.php/api/uploadclass/uploadtauky/"]];         nsmutableurlrequest *request = [[nsmutableurlrequest alloc] init] ;         [request seturl:[nsurl urlwithstring:urlstring]];         [request sethttpmethod:@"post"];          nsstring *boundary = @"---------------------------14737809831466499882746641449";         nsstring *contenttype = [nsstring stringwithformat:@"multipart/form-data; boundary=%@",boundary];         [request addvalue:contenttype forhttpheaderfield: @"content-type"];          nsmutabledata *body = [nsmutabledata data];    [body appenddata:[[nsstring stringwithformat:@"--%@\r\n", boundary] datausingencoding:nsutf8stringencoding]];         [body appenddata:[[nsstring stringwithformat:@"content-disposition: form-data; name=\"caption\"\r\n\r\n"] datausingencoding:nsutf8stringencoding]];         [body appenddata:[captionn datausingencoding:nsutf8stringencoding]];         [body appenddata:[[nsstring stringwithstring:@"\r\n"] datausingencoding:nsutf8stringencoding]];         // text parameter         [body appenddata:[[nsstring stringwithformat:@"--%@\r\n", boundary] datausingencoding:nsutf8stringencoding]];         [body appenddata:[[nsstring stringwithformat:@"content-disposition: form-data; name=\"user_id\"\r\n\r\n"] datausingencoding:nsutf8stringencoding]];         [body appenddata:[user_idd datausingencoding:nsutf8stringencoding]];         [body appenddata:[[nsstring stringwithstring:@"\r\n"] datausingencoding:nsutf8stringencoding]];           // text parameter         [body appenddata:[[nsstring stringwithformat:@"--%@\r\n", boundary] datausingencoding:nsutf8stringencoding]];         [body appenddata:[[nsstring stringwithformat:@"content-disposition: form-data; name=\"mobile_tauky_id\"\r\n\r\n"] datausingencoding:nsutf8stringencoding]];         [body appenddata:[mobile_tauky_idd datausingencoding:nsutf8stringencoding]];         [body appenddata:[[nsstring stringwithstring:@"\r\n"] datausingencoding:nsutf8stringencoding]];            // text parameter         [body appenddata:[[nsstring stringwithformat:@"--%@\r\n", boundary] datausingencoding:nsutf8stringencoding]];         [body appenddata:[[nsstring stringwithformat:@"content-disposition: form-data; name=\"blauky_id\"\r\n\r\n"] datausingencoding:nsutf8stringencoding]];         [body appenddata:[blauky_idd datausingencoding:nsutf8stringencoding]];         [body appenddata:[[nsstring stringwithstring:@"\r\n"] datausingencoding:nsutf8stringencoding]];         // file         [body appenddata:[[nsstring stringwithformat:@"--%@\r\n", boundary] datausingencoding:nsutf8stringencoding]];         [body appenddata:[[nsstring stringwithstring:@"content-disposition: imagedata; name=\"elephant\"; filename=\".jpg\"\r\n"] datausingencoding:nsutf8stringencoding]];         [body appenddata:[[nsstring stringwithstring:@"content-type: application/octet-stream\r\n\r\n"] datausingencoding:nsutf8stringencoding]];         [body appenddata:[nsdata datawithdata:imagedata]];         [body appenddata:[[nsstring stringwithstring:@"\r\n"] datausingencoding:nsutf8stringencoding]];          // file         [body appenddata:[[nsstring stringwithformat:@"--%@\r\n", boundary] datausingencoding:nsutf8stringencoding]];         [body appenddata:[[nsstring stringwithstring:@"content-disposition: audiodata; name=\"ch\"; filename=\".mp3\"\r\n"] datausingencoding:nsutf8stringencoding]];         [body appenddata:[[nsstring stringwithstring:@"content-type: application/octet-stream\r\n\r\n"] datausingencoding:nsutf8stringencoding]];         [body appenddata:[nsdata datawithdata:audiodata]];         [body appenddata:[[nsstring stringwithstring:@"\r\n"] datausingencoding:nsutf8stringencoding]];         // close form         [body appenddata:[[nsstring stringwithformat:@"--%@--\r\n", boundary] datausingencoding:nsutf8stringencoding]];          // set request body         [request sethttpbody:body];     nslog(@"%@",body);  nsdata *returndata = [nsurlconnection sendsynchronousrequest:request returningresponse:nil error:nil];         nsstring *returnstring = [[nsstring alloc] initwithdata:returndata encoding:nsutf8stringencoding];         nslog(@"response : %@",returnstring);          if([returnstring isequaltostring:@"success ! file has been uploaded"])         {             uialertview *alert = [[uialertview alloc] initwithtitle:@"success" message:@"image saved successfully" delegate:self cancelbuttontitle:@"ok" otherbuttontitles:nil];              [alert show];         }         nslog(@"finish"); 

can body tell me mistake in code. have enter parameters compulsary caption, user_id, mobile_tauky_id, blauky_id, image, audio

i using asiformdatarequest same, working fine , give response in seconds.

uiimage * img = [uiimage imagenamed:@"elephant.jpg"]; nsdata *imagedata = uiimagepngrepresentation(img);  nsstring *strurl =your url"; asiformdatarequest *request = [asiformdatarequest requestwithurl:[nsurl urlwithstring:strurl]]; [request setdelegate:self]; [request setpostvalue:@"avanvsj767uysuyas" forkey:@"imei"]; [request setpostvalue:cardname forkey:@"customername"]; [request setpostvalue:@"varun@gmail.com" forkey:@"customeremailid"]; [request adddata:imagedata withfilename:@"image" andcontenttype:@"image/png" forkey:@"filename1"]; [request setdelegate:self]; [request startasynchronous]; 

Comments

Popular posts from this blog

blackberry 10 - how to add multiple markers on the google map just by url? -

php - guestbook returning database data to flash -

delphi - Dynamic file type icon -