http post - Android - image upload sending no content -


i've been looking last day or 2 , can not seem find solution issue. trying post image server using httppost. have tried 2 ways of doing , both complete post no content i.e. content length 0. first follows:

string url = "myurl";         httpclient httpclient = new defaulthttpclient();       try {              httpclient.getparams().setparameter("http.socket.timeout", new integer(90000)); // 90 second              httppost post = new httppost(url);              file sdcardroot = environment.getexternalstoragedirectory();              file file = new file(sdcardroot,"/dcim/100msdcf/dsc00004.jpg");              fileentity entity;              entity = new fileentity(file,"binary/octet-stream");              entity.setchunked(true);              post.setentity(entity);              post.addheader("header", "uniquename");              httpresponse response = httpclient.execute(post);              if (response.getstatusline().getstatuscode() != httpstatus.sc_ok) {                      log.e("here","--------error--------response status line code:"+response.getstatusline());              }else {                      // here every thing fine.              }               httpentity resentity = response.getentity();              if (resentity == null) {                  log.e("here","---------error no response!!-----");              }      } catch (exception ex) {              log.e("here","---------error-----"+ex.getmessage());              ex.printstacktrace();      } {                httpclient.getconnectionmanager().shutdown();      } 

and second is:

string url = "myurl";         //file sdcardroot = environment.getexternalstoragedirectory();         file file = new file(environment.getexternalstoragedirectory(),"/dcim/100msdcf/dsc00004.jpg");         try {             httpclient httpclient = new defaulthttpclient();             httppost httppost = new httppost(url);             inputstreamentity reqentity = new inputstreamentity(new fileinputstream(file), -1);             reqentity.setcontenttype("binary/octet-stream");             reqentity.setchunked(true);             // send in multiple parts if needed             httppost.setentity(reqentity);             httpresponse response = httpclient.execute(httppost);             log.d("finishing", "the try catch function");         } catch (exception e) {             // show error         }*/ 

as can see have hardcoded path specific image, dynamic when , running. can see i'm doing wrong? leaving out something? know use setchunked , setcontenttype - there setcontent option? grately appreciated.

thanks, jr83.

you can use upload image sending multipart messages; might find this discussion useful.


Comments

Popular posts from this blog

apache - Add omitted ? to URLs -

redirect - bbPress Forum - rewrite to wwww.mysite prohibits login -

php - How can I stop spam on my custom forum/blog? -