http post - how can i send imagedata on server using httppost in android? -
i tried convert image data "string str=base64.encodetostring(imagedata, base64.default);" , tried send not working.
even tried below,
multipartentitybuilder builder = multipartentitybuilder.create(); builder.setcharset(mime.utf8_charset); builder.addbinarybody("file",imagedata); httppost.setentity(builder.build());
still can't send image.
server url on trying send below,
"http://192.168.1.8:88/erp/demo.nsf/(demo)?operation&file=imagedata"
please give me suggestions.
thank you.
i don't think url supposed carry parameters. parameters use must added in builder text. here's code used same thing.:
@override protected string doinbackground(string... params) { // todo auto-generated method stub string textfilename = params[0]; string message = "this multipart post"; string result =" "; httppost post = new httppost("http://10.0.2.2/test/upload_file_test.php"); file file = new file(textfilename); multipartentitybuilder builder = multipartentitybuilder.create(); builder.setmode(httpmultipartmode.browser_compatible); builder.addbinarybody("uploaded_file", file, contenttype.default_binary, textfilename); builder.addtextbody("text", message, contenttype.default_binary); httpentity entity = builder.build(); post.setentity(entity); httpclient client = new defaulthttpclient(); try { httpresponse response = client.execute(post); 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); } system.out.println("response: " + s); } catch (clientprotocolexception e) { // todo auto-generated catch block e.printstacktrace(); } catch (ioexception e) { // todo auto-generated catch block e.printstacktrace(); } return message; } }
i used text part send message image.
Comments
Post a Comment