mirror of
https://gitee.com/binary/weixin-java-tools.git
synced 2025-06-28 13:16:19 +08:00
修复重构素材上传处理代码
This commit is contained in:
parent
bc22b03ea3
commit
13d76c1c50
@ -30,23 +30,27 @@ public class MaterialUploadRequestExecutor implements RequestExecutor<WxMpMateri
|
||||
httpPost.setConfig(response);
|
||||
}
|
||||
|
||||
if (material != null) {
|
||||
File file = material.getFile();
|
||||
if (file == null || !file.exists()) {
|
||||
throw new FileNotFoundException();
|
||||
}
|
||||
MultipartEntityBuilder multipartEntityBuilder = MultipartEntityBuilder.create();
|
||||
multipartEntityBuilder
|
||||
.addBinaryBody("media", file)
|
||||
.setMode(HttpMultipartMode.RFC6532);
|
||||
Map<String, String> form = material.getForm();
|
||||
if (material.getForm() != null) {
|
||||
multipartEntityBuilder.addTextBody("description", WxGsonBuilder.create().toJson(form));
|
||||
}
|
||||
httpPost.setEntity(multipartEntityBuilder.build());
|
||||
httpPost.setHeader("Content-Type", ContentType.MULTIPART_FORM_DATA.toString());
|
||||
if (material == null) {
|
||||
throw new WxErrorException(WxError.newBuilder().setErrorMsg("非法请求,material参数为空").build());
|
||||
}
|
||||
|
||||
File file = material.getFile();
|
||||
if (file == null || !file.exists()) {
|
||||
throw new FileNotFoundException();
|
||||
}
|
||||
|
||||
MultipartEntityBuilder multipartEntityBuilder = MultipartEntityBuilder.create();
|
||||
multipartEntityBuilder
|
||||
.addBinaryBody("media", file)
|
||||
.setMode(HttpMultipartMode.RFC6532);
|
||||
Map<String, String> form = material.getForm();
|
||||
if (material.getForm() != null) {
|
||||
multipartEntityBuilder.addTextBody("description", WxGsonBuilder.create().toJson(form));
|
||||
}
|
||||
|
||||
httpPost.setEntity(multipartEntityBuilder.build());
|
||||
httpPost.setHeader("Content-Type", ContentType.MULTIPART_FORM_DATA.toString());
|
||||
|
||||
try (CloseableHttpResponse response = httpclient.execute(httpPost)) {
|
||||
String responseContent = Utf8ResponseHandler.INSTANCE.handleResponse(response);
|
||||
WxError error = WxError.fromJson(responseContent);
|
||||
@ -55,7 +59,7 @@ public class MaterialUploadRequestExecutor implements RequestExecutor<WxMpMateri
|
||||
} else {
|
||||
return WxMpMaterialUploadResult.fromJson(responseContent);
|
||||
}
|
||||
}finally {
|
||||
} finally {
|
||||
httpPost.releaseConnection();
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user