Skip to content

Commit b56973f

Browse files
committed
Merge branch 'binarywang-develop' into develop
2 parents b403551 + defd54b commit b56973f

File tree

1 file changed

+3
-4
lines changed

1 file changed

+3
-4
lines changed

weixin-java-mp/src/main/java/me/chanjar/weixin/mp/util/http/MaterialUploadRequestExecutor.java

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -15,14 +15,14 @@
1515
import org.apache.http.entity.ContentType;
1616
import org.apache.http.entity.mime.HttpMultipartMode;
1717
import org.apache.http.entity.mime.MultipartEntityBuilder;
18-
import org.apache.http.entity.mime.content.InputStreamBody;
1918
import org.apache.http.impl.client.CloseableHttpClient;
2019

2120
import java.io.*;
2221
import java.util.Map;
2322

2423
public class MaterialUploadRequestExecutor implements RequestExecutor<WxMpMaterialUploadResult, WxMpMaterial> {
2524

25+
@Override
2626
public WxMpMaterialUploadResult execute(CloseableHttpClient httpclient, HttpHost httpProxy, String uri, WxMpMaterial material) throws WxErrorException, ClientProtocolException, IOException {
2727
HttpPost httpPost = new HttpPost(uri);
2828
if (httpProxy != null) {
@@ -35,10 +35,9 @@ public WxMpMaterialUploadResult execute(CloseableHttpClient httpclient, HttpHost
3535
if (file == null || !file.exists()) {
3636
throw new FileNotFoundException();
3737
}
38-
BufferedInputStream bufferedInputStream = new BufferedInputStream(new FileInputStream(file));
3938
MultipartEntityBuilder multipartEntityBuilder = MultipartEntityBuilder.create();
4039
multipartEntityBuilder
41-
.addPart("media", new InputStreamBody(bufferedInputStream, material.getName()))
40+
.addBinaryBody("media", file)
4241
.setMode(HttpMultipartMode.RFC6532);
4342
Map<String, String> form = material.getForm();
4443
if (material.getForm() != null) {
@@ -48,7 +47,7 @@ public WxMpMaterialUploadResult execute(CloseableHttpClient httpclient, HttpHost
4847
httpPost.setHeader("Content-Type", ContentType.MULTIPART_FORM_DATA.toString());
4948
}
5049

51-
try(CloseableHttpResponse response = httpclient.execute(httpPost)){
50+
try (CloseableHttpResponse response = httpclient.execute(httpPost)) {
5251
String responseContent = Utf8ResponseHandler.INSTANCE.handleResponse(response);
5352
WxError error = WxError.fromJson(responseContent);
5453
if (error.getErrorCode() != 0) {

0 commit comments

Comments
 (0)