java - Upload image File to server wich work on php -
i want upload image file mobile phone on android server. have url , must send image file in filed 'file' use robospice robospice-google-http-client
. code this:
public class loadfileonserverrequest extends googlehttpclientspicerequest<loadfilemodel> { hashmap<string, object> postparam; public loadfileonserverrequest(file file) { super(loadfilemodel.class); postparam = new hashmap<>(); postparam.put("file", file); setretrypolicy(null); } @override public loadfilemodel loaddatafromnetwork() throws exception { genericurl genericurl = new genericurl("http://testwb/ajax_scripts/file.php"); httpcontent content = new urlencodedcontent(postparam); httprequest request = buildpostrequest(genericurl, content); request.setparser(new jacksonfactory().createjsonobjectparser()); httpresponse response = request.execute(); return response.parseas(getresulttype()); } private httprequest buildpostrequest(genericurl genericurl, httpcontent content) throws ioexception { system.setproperty("http.keepalive", "false"); httprequest request = gethttprequestfactory().buildpostrequest(genericurl, content); customhttpheader(request); return request; } private void customhttpheader(httprequest request) { request.getheaders().setacceptencoding("gzip, deflate"); request.getheaders().setaccept("*/*"); request.getheaders().setcontenttype("multipart/form-data; boundary=----webkitformboundarycito9o2o3nbgvjgm"); }
but server don't see file. sees request, without file. when send file on url through rest client in browser, receive answer link. wrong? may error in server side ?
this simple example upload file on server may you.
just take @ here
you can make further changes according requirements
Comments
Post a Comment