android - How to post zip file with two string params -


byte[] binary = fileutils.readfiletobytearray(reportfile);     typedinput bininput = new typedbytearray("application/zip", binary);     restadapter restadapter = new restadapter.builder()             .setendpoint(contextconstants.report_submit_path)             .build();     restadapter.setloglevel(restadapter.loglevel.full);     http = restadapter.create(customhttpservice.class);     http.sendreport(stringbuffer.tostring(), (usercomments != null) ? usercomments : "", bininput, new callback<string>() {         @override         public void success(string s, response response) {             if (response.getstatus() == 200) {              }         }          @override         public void failure(retrofiterror error) {             logger.error("retrofiterror code: " + error.getmessage());         }     }); 

interface:

@formurlencoded @post("/collectfeedback") void sendreport(@field("deviceinfo") string deviceinfo, @field("garbageinfo") string garbageinfo,                 @body typedinput binary, callback<string> response); 

i`m getting such kinda error:

retrofit.retrofiterror: customhttpservice.sendreport: @body parameters cannot used form or multi-part encoding. (parameter #3)

here solved issue:

@multipart @post("/collectfeedback") void sendreport(@part("deviceinfo") typedstring  deviceinfo, @part("garbageinfo") typedstring  garbageinfo,                 @part("archive") typedfile file, callback<string> response); 

and interface`s implementation:

typedstring deviceinfo = new typedstring(stringbuffer.tostring());     typedstring garbageinfo = new typedstring((usercomments != null) ? usercomments : "");     typedfile archivefile = new typedfile("application/zip", reportfile);     restadapter restadapter = new restadapter.builder()             .setendpoint(contextconstants.report_submit_path)             .build();     http = restadapter.create(customhttpservice.class);     http.sendreport(deviceinfo, garbageinfo, archivefile, new callback<string>() {         @override         public void success(string s, response response) {             logger.info("response code: " + response.getstatus());             if (response.getstatus() == 200) {                 boolean deleteresult = reporthelper.deletecrashdumpfiles();                 logger.info("deletefile result: " + deleteresult);             }         }          @override         public void failure(retrofiterror error) {             logger.error("retrofiterror code: " + error.getmessage());         }     }); 

Comments

Popular posts from this blog

html - Outlook 2010 Anchor (url/address/link) -

javascript - Why does running this loop 9 times take 100x longer than running it 8 times? -

Getting gateway time-out Rails app with Nginx + Puma running on Digital Ocean -