objective c - Uploading image to server via node.js from an iOS app -


i developing ios app , using node.js server side scripting. facing problem in uploading image server ios app. working fine if uploading image webpage form. if uploading app side not working.

 //test file  h3 pic upload  form(action='/pic_upload', method='post',enctype='multipart/form-data')    | user_pic:   input(type='file', name='user_pic')   input(type='submit')   //app.js  var userlogin =require('./routes/userlogin');  app.post('/pic_upload', userlogin.picupload);  //userlogin.js //picupload function exports.picupload = function(req, res) { console.log(req.files);  // showing undefined, when called ios app // pic upload script... }); 

i have tried sending image app side data or file parameter did not work. how send file parameter app side can upload image server? kindly suggest way tackle problem.

this code works in app. try this.

nsdata *imgdata = uiimagejpegrepresentation(newimg, 0.2);  nsstring *str = @"displayimage";      nsstring *urlstring = @"http://some.url.com/post";      // create request     nsmutableurlrequest *request = [[nsmutableurlrequest alloc] init];     [request setcachepolicy:nsurlrequestreloadignoringlocalcachedata];     [request sethttpshouldhandlecookies:no];     [request settimeoutinterval:30];     [request seturl:[nsurl urlwithstring:urlstring]];      [request sethttpmethod:@"post"];      nsstring *boundary = [nsstring stringwithformat:@"---------------------------14737809831464368775746641449"];      // set content-type in http header     nsstring *contenttype = [nsstring stringwithformat:@"multipart/form-data; boundary=%@", boundary];     [request setvalue:contenttype forhttpheaderfield: @"content-type"];      // post body     nsmutabledata *body = [nsmutabledata data];      // add params (all params strings)         [body appenddata:[[nsstring stringwithformat:@"\r\n--%@\r\n", boundary] datausingencoding:nsutf8stringencoding]];         [body appenddata:[[nsstring stringwithformat:@"content-disposition: form-data; name=\"currenteventid\"\r\n\r\n"] datausingencoding:nsutf8stringencoding]];         [body appenddata:[@"52344457901000006" datausingencoding:nsutf8stringencoding]];       // add image data     if (imgdata) {         [body appenddata:[[nsstring stringwithformat:@"\r\n--%@\r\n", boundary] datausingencoding:nsutf8stringencoding]];        // [body appenddata:[nsstring stringwithformat:@"content-disposition: form-data; name=\"displayimage\"; filename=\"image.jpg\"\r\n"]];         [body appenddata:[[nsstring stringwithformat:@"content-disposition: form-data; name=\"%@\"; filename=\"image.jpg\"\r\n", str] datausingencoding:nsutf8stringencoding]];          [body appenddata:[@"content-type: image/jpeg\r\n\r\n" datausingencoding:nsutf8stringencoding]];         [body appenddata:imgdata];         [body appenddata:[[nsstring stringwithformat:@"\r\n"] datausingencoding:nsutf8stringencoding]];     }      [body appenddata:[[nsstring stringwithformat:@"\r\n--%@--\r\n", boundary] datausingencoding:nsutf8stringencoding]];      // setting body of post reqeust     [request sethttpbody:body];      // set url     [request seturl:[nsurl urlwithstring:urlstring]];      nsstring *bodystr = [[nsstring alloc]initwithdata:body encoding:nsutf8stringencoding];     nslog(@" %@",bodystr);      nsurlconnection *lot_connection=[[nsurlconnection alloc]initwithrequest:request delegate:self];      if(lot_connection)     {         webdata = [[nsmutabledata alloc] init];      } 

Comments

Popular posts from this blog

html - How to style widget with post count different than without post count -

How to remove text and logo OR add Overflow on Android ActionBar using AppCompat on API 8? -

javascript - storing input from prompt in array and displaying the array -