android - Select multiple images from the sdcard and upload them to a server -
my code:
protected string doinbackground(httpresponse... arg0) { string result = ""; file file = new file(selectimages); try { httpclient client = new defaulthttpclient(); string posturl = "http://192.168.1.11/api/review/add_image.php?"; post = new httppost(posturl); filebody bin = new filebody(file); totalsize = bin.getcontentlength(); multipartentity reqentity = new multipartentity(httpmultipartmode.browser_compatible, new progresslistener() { public void transferred(long num) { publishprogress((int) ((num / (float) totalsize) * 100)); } }); reqentity.addpart("userfile", bin); post.setentity(reqentity); httpresponse response = client.execute(post); httpentity resentity = response.getentity(); if (resentity != null) { result = entityutils.tostring(resentity); } } catch (exception e) { e.printstacktrace(); } return result; }
my result null.
this nice way convert image base64. can send more images in easy way.
imageview.builddrawingcache(); bitmap bm = imageview.getdrawingcache(); bytearrayoutputstream baos = new bytearrayoutputstream(); bm.compress(bitmap.compressformat.jpeg, 100, baos); //bm bitmap object byte[] b = baos.tobytearray(); string encodedimage = base64.encodetostring(b , base64.default);
if have 5 images can add them array , send server.
Comments
Post a Comment