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

Allow access to named sections of a multipart request body [SPR-8483] #13129

Closed
spring-projects-issues opened this issue Jun 23, 2011 · 1 comment
Assignees
Labels
in: web Issues in web modules (web, webmvc, webflux, websocket) type: enhancement A general enhancement
Milestone

Comments

@spring-projects-issues
Copy link
Collaborator

spring-projects-issues commented Jun 23, 2011

nebhale opened SPR-8483 and commented

Currently when a multipart request is received via a POST call, the only way to reference the sections of that request is by using the @ReqestParam(<name>) annotation to get the body content. The content that you might get is then limited as it can only be converted to simple types (it doesn't go through the ConversionService) and you must do any conversion yourself.

Ideally, it'd be nice to have an @RequestPart(<name>) annotation that would allow you to reference the sections of the request and the values there would go through standard @RequestBody processing for things like ConversionService conversion and @Valid validation.


Affects: 3.1 M2

Issue Links:

Referenced from: commits 3a87d8e, 3363d05, f4b7cfe

@spring-projects-issues
Copy link
Collaborator Author

Rossen Stoyanchev commented

When sending JSON data using RestTemplate's postForEntity method and a MultiValueMap:

MultiValueMap<String, Object> request = new LinkedMultiValueMap<String, Object>();
request.add("meta-data", new JSONObject().accumulate("version", "testVersion").accumulate("name", "testName"));
request.add("file-data", TEMPLATE_IMAGE);

The signature of the controller method:

@RequestMapping(value = "", method = RequestMethod.POST, consumes = { "multipart/mixed", "multipart/form-data" })
final ResponseEntity<T> create(@RequestPart("meta-data") UnnamedImageInput input, @RequestPart("file-data") MultipartFile file) {

}

Results in the following failure:

java.lang.IllegalArgumentException: Request part named 'meta-data' not found. Available request part names: [file-data]
    at org.springframework.util.Assert.notNull(Assert.java:112)
    at org.springframework.web.multipart.RequestPartServletServerHttpRequest.<init>(RequestPartServletServerHttpRequest.java:54)

On the server side the DefaultMultipartHttpServletRequest contains a multipart file named "file-data", but no multipart file named "meta-data". Instead it does contain a multipart parameter named "meta-data" and it's value is the JSON string.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
in: web Issues in web modules (web, webmvc, webflux, websocket) type: enhancement A general enhancement
Projects
None yet
Development

No branches or pull requests

2 participants