文件正确上传.但是,如果文件名包含非ASCII字符,则会以“ ???.jpg”
设置setCharset,之后再设置setMode即可
MultipartEntityBuilder b = MultipartEntityBuilder.create();
b.addPart("file", new FileBody(<FILE>, <CONTENTTYPE>, <FILENAME>)).setMode(HttpMultipartMode.BROWSER_COMPATIBLE);
b.setCharset(StandardCharsets.UTF_8);
CloseableHttpClient httpclient = HttpClients.createDefault();
HttpPost post = new HttpPost(url);
post.setConfig(RequestConfig.DEFAULT);
post.addHeader(HTTP.CONTENT_ENCODING, "UTF-8");
MultipartEntityBuilder entityBuilder = MultipartEntityBuilder.create();
entityBuilder.setCharset(StandardCharsets.UTF_8);
for (MultipartFile filesPart: filesParts) {
InputStreamBody inputStreamBody = new InputStreamBody(filesPart.getInputStream(), filesPart.getOriginalFilename());
entityBuilder.addPart("files", inputStreamBody).setMode(HttpMultipartMode.BROWSER_COMPATIBLE);
}
post.setEntity(entityBuilder.build());