Andrew Neeson opened SPR-16808 and commented
I had a need to proxy a MultipartFile from a controller to a RestTemplate. I did not want the contents of this file to be stored locally (as with FileSystemResource or ByteArrayResource) so I created a MultipartFileResource.
I though this would be a useful addition to Spring's resource types, so I intended to submit a pull request. Upon searching for similar issues I found #18147.
After reading through the comments, my understanding was that the resource wasn't created because of issues opening the InputStream twice. Once for the getInputStream() call and another by the contentLength() call (by virtue of AbstractResource using the inputstream to calculate this value).
However a MultipartFile already provides the content length (without accessing the InputStream). So why not use that? I.e.
@Override
public long contentLength() throws IOException {
return multipartFile.getSize();
}
Assuming that:
I would like Spring to include a MultipartFileResource. I'd be happy to submit a PR.
Affects: 5.0.6
Issue Links:
Andrew Neeson opened SPR-16808 and commented
I had a need to proxy a
MultipartFilefrom a controller to aRestTemplate. I did not want the contents of this file to be stored locally (as withFileSystemResourceorByteArrayResource) so I created aMultipartFileResource.I though this would be a useful addition to Spring's resource types, so I intended to submit a pull request. Upon searching for similar issues I found #18147.
After reading through the comments, my understanding was that the resource wasn't created because of issues opening the InputStream twice. Once for the
getInputStream()call and another by thecontentLength()call (by virtue ofAbstractResourceusing the inputstream to calculate this value).However a
MultipartFile already provides the content length (without accessing the InputStream). So why not use that? I.e.Assuming that:
I would like Spring to include a
MultipartFileResource. I'd be happy to submit a PR.Affects: 5.0.6
Issue Links: