java - MultipartEntityBuilder adds Content-Disposition header to binary file and corrupts it -
java - MultipartEntityBuilder adds Content-Disposition header to binary file and corrupts it -
i have java snippet of code sends binary file through web rest client, unfortunately multipartentitybuilder encodes binary file adds headers corrupt file, instance adds content-disposition not nowadays in original file.
how can prepare this?
closeablehttpclient httpclient = httpclientbuilder.create().build(); httppost httppost = new httppost(getremoteurlstring() + "/webresources/file/upload"); multipartentitybuilder multipartentitybuilder = multipartentitybuilder.create(); multipartentitybuilder.setmode(httpmultipartmode.strict); multipartentitybuilder.setboundary("custyom-mimetype-boundary"); multipartentitybuilder.addpart("filename", (stringbody) valueslist.get(0)); multipartentitybuilder.addpart("file", (filebody) valueslist.get(1)); httppost.setentity(multipartentitybuilder.build()); httppost.setentity(multipartentitybuilder.build()); httpresponse response = null; seek { response = httpclient.execute(httppost); } grab (ioexception ex) { }
only solution found leave headers on sending side , modify receiving side, apparently readbodydata function reads headers if don't first read headers , discard them.
//we read uselessheaders otherwise readbodydata includes them , corrupts files string uselessheaders = multipartstream.readheaders(); multipartstream.readbodydata(bytearrayoutputstream);
java rest multipartform-data
Comments
Post a Comment