Skip to content

Commit 4bee1ba

Browse files
committed
#165 MediaDownloadRequestExecutor出错后就没有办法下载了
1 parent f30211c commit 4bee1ba

File tree

1 file changed

+16
-9
lines changed

1 file changed

+16
-9
lines changed

weixin-java-common/src/main/java/me/chanjar/weixin/common/util/http/MediaDownloadRequestExecutor.java

Lines changed: 16 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -63,16 +63,23 @@ public File execute(CloseableHttpClient httpclient, HttpHost httpProxy, String u
6363
throw new WxErrorException(WxError.fromJson(responseContent));
6464
}
6565
}
66-
InputStream inputStream = InputStreamResponseHandler.INSTANCE.handleResponse(response);
67-
68-
// 视频文件不支持下载
69-
String fileName = getFileName(response);
70-
if (StringUtils.isBlank(fileName)) {
71-
return null;
66+
InputStream inputStream = null;
67+
try {
68+
inputStream = InputStreamResponseHandler.INSTANCE.handleResponse(response);
69+
70+
// 视频文件不支持下载
71+
String fileName = getFileName(response);
72+
if (StringUtils.isBlank(fileName)) {
73+
return null;
74+
}
75+
String[] name_ext = fileName.split("\\.");
76+
File localFile = FileUtils.createTmpFile(inputStream, name_ext[0], name_ext[1], tmpDirFile);
77+
return localFile;
78+
} finally {
79+
if (inputStream != null) {
80+
inputStream.close();
81+
}
7282
}
73-
String[] name_ext = fileName.split("\\.");
74-
File localFile = FileUtils.createTmpFile(inputStream, name_ext[0], name_ext[1], tmpDirFile);
75-
return localFile;
7683
}
7784

7885
protected String getFileName(CloseableHttpResponse response) {

0 commit comments

Comments
 (0)