private class MultipartFileResource extends InputStreamResource {

private String fileName;

private InputStream inputStream;

public MultipartFileResource(InputStream inputStream, String fileName) {
super(inputStream);
this.inputStream = inputStream;
this.fileName = fileName;
}

@Override
public String getFilename() {
return this.fileName;
}

@Override
public long contentLength() throws IOException {
return inputStream.available();
}

@Override
public boolean equals(Object obj) {
return (obj == this || (obj instanceof MultipartFileResource && ((MultipartFileResource) obj).inputStream.equals(this.inputStream)));
}
}

 

调用方法:

List<MultipartFile> files

for (MultipartFile file : files) {
map.add("file", new MultipartFileResource(file.getInputStream(), file.getOriginalFilename()));
}

相关文章:

  • 2021-10-18
  • 2022-01-29
  • 2021-10-31
  • 2022-12-23
  • 2021-06-13
  • 2022-12-23
  • 2021-11-20
  • 2021-07-16
猜你喜欢
  • 2022-12-23
  • 2022-12-23
  • 2021-05-31
  • 2022-12-23
  • 2021-04-04
  • 2022-12-23
  • 2021-07-05
相关资源
相似解决方案