Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support use of MultipartFile as input to RestTemplate or WebClient [SPR-16808] #21348

Closed
spring-projects-issues opened this issue May 10, 2018 · 2 comments
Assignees
Labels
in: core Issues in core modules (aop, beans, core, context, expression) type: enhancement A general enhancement
Milestone

Comments

@spring-projects-issues
Copy link
Collaborator

spring-projects-issues commented May 10, 2018

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:

@spring-projects-issues
Copy link
Collaborator Author

Rossen Stoyanchev commented

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.

@spring-projects-issues
Copy link
Collaborator Author

Andrew Neeson commented

rstoyanchev+1

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
in: core Issues in core modules (aop, beans, core, context, expression) type: enhancement A general enhancement
Projects
None yet
Development

No branches or pull requests

2 participants