Closed
Description
@binarywang
在进行批量公众账号图文素材上传的过程中,需要频繁的对一个文件进行读取操作, 发现下次循环的时候,io流已经关闭.希望优化方法
WxMpMaterialServiceImpl
@Override
public WxMediaUploadResult mediaUpload(String mediaType, String fileType, InputStream inputStream) throws WxErrorException {
File tmpFile = null;
try {
tmpFile = FileUtils.createTmpFile(inputStream, UUID.randomUUID().toString(), fileType);
return this.mediaUpload(mediaType, tmpFile);
} catch (IOException e) {
throw new WxErrorException(WxError.builder().errorCode(-1).errorMsg(e.getMessage()).build(), e);
} finally {
if (tmpFile != null) {
tmpFile.delete();
}
}
}
/* *
* 优化新增方法
*/
public WxMediaUploadResult mediaUpload(String mediaType, String fileType, InputStream inputStream, boolean isCloseStream) throws WxErrorException {
File tmpFile = null;
try {
tmpFile = FileUtils.createTmpFile(inputStream, UUID.randomUUID().toString(), fileType);
return this.mediaUpload(mediaType, tmpFile);
} catch (IOException e) {
throw new WxErrorException(WxError.builder().errorCode(-1).errorMsg(e.getMessage()).build(), e);
} finally {
if (tmpFile != null) {
tmpFile.delete();
}
}
}