You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Support use of MultipartFile as input to RestTemplate or WebClient [SPR-16808] #21348
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.
Juergen Hoeller, what about exposing a getResource method on MultipartFile? That saves the need for a public, custom implementation of Resource and exposes the option where it's easy to discover. It lines well next to getInputStream.
It could be done as a default method that builds on getInputStream and getOriginalFileName and creates a package-private implementation of Resource.
Activity
spring-projects-issues commentedon May 10, 2018
Rossen Stoyanchev commented
Juergen Hoeller, what about exposing a
getResourcemethod onMultipartFile? That saves the need for a public, custom implementation ofResourceand exposes the option where it's easy to discover. It lines well next togetInputStream.It could be done as a default method that builds on
getInputStreamandgetOriginalFileNameand creates a package-private implementation of Resource.spring-projects-issues commentedon May 11, 2018
Andrew Neeson commented
rstoyanchev+1