php - Upload an image AND send text with $_POST through an android app -


i have upload image server send text. ive done, doesn't work:

string  uploadimage(bitmap bm) {     string resp = null;     try {           bytearrayoutputstream bos = new bytearrayoutputstream();         bm.compress(compressformat.jpeg, 75, bos);         byte[] data = bos.tobytearray();          httpclient httpclient = new defaulthttpclient();         httppost postrequest = new httppost("myserver.com/add.php");         string rndname =generatesessionkey(15);          list<namevaluepair> namevaluepair = new arraylist<namevaluepair>(1);         namevaluepair.add(new basicnamevaluepair("filename",rndname));         namevaluepair.add(new basicnamevaluepair("email",email));          urlencodedformentity form;         form = new urlencodedformentity(namevaluepair);         form.setcontentencoding(http.utf_8);         try {             postrequest.setentity((httpentity) new urlencodedformentity(namevaluepair,"utf-8"));         } catch (unsupportedencodingexception e) {             // writing error log             e.printstacktrace();         }          bytearraybody bab = new bytearraybody(data,rndname+".jpg");          multipartentity reqentity = new multipartentity(httpmultipartmode.browser_compatible);         reqentity.addpart("uploaded", bab);         //reqentity.addpart("photocaption", new stringbody("sfsdfsdf"));         postrequest.setentity(reqentity);         httpresponse response = httpclient.execute(postrequest);         bufferedreader reader = new bufferedreader(new inputstreamreader(response.getentity().getcontent(), "utf-8"));         string sresponse;         stringbuilder s = new stringbuilder();         while ((sresponse = reader.readline()) != null) {             s = s.append(sresponse);         }         resp=s.tostring();     } catch (exception e) {         // handle exception here         log.e(e.getclass().getname(), e.getmessage());     }     return resp; } 

the server doesnt filename , email.

why doesn't work?

thanks assistance!

you can not combine urlencoded , multipart. instead, add string fields own part of multipart.

look here example: apache httpclient making multipart form post


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 -