8000 文件上传接口优化,添加支持是否关闭io流的方法 · Issue #591 · binarywang/WxJava · GitHub
[go: up one dir, main page]

Skip to content
文件上传接口优化,添加支持是否关闭io流的方法 #591
Closed
@15838028035

Description

@15838028035

@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();
      }
    }
  }

Metadata

Metadata

Assignees

No one assigned

    Labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions

      0