-
Notifications
You must be signed in to change notification settings - Fork 38.3k
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
MockPart in request is not recieved in RequestPart in controller #26501
Comments
This is likely a duplicate of #26400. Could you check if it works 5.3.4-SNAPSHOT? |
Yes, I already tried running it with spring-test:5.3.4-SNAPSHOT but the result is still a "null" value in the controller. |
I extracted a simple snippet for testing: https://github.com/LickIt/spring-mockpart-issue @Test
public void testUpload() throws Exception {
MockMultipartFile file = new MockMultipartFile("file", "file.png", "application/octet-stream", new byte[0]);
MockPart label = new MockPart("label", "mainImage".getBytes(UTF_8));
mockMvc.perform(multipart("/test").file(file).part(label))
.andExpect(content().string("mainImage"));
} Here is the controller method: @PostMapping(path = "/test", consumes = MediaType.MULTIPART_FORM_DATA_VALUE)
public String uploadFile(@RequestParam("file") MultipartFile file,
@RequestPart(value = "label", required = false) String label) {
return label;
} |
Thanks for the sample. The latest code adds both a From
From RFC 7578 says:
I think the Javadoc for What do you think @jhoeller ? |
This should be fixed in the latest snapshots. If you could, please give it another try. |
@rstoyanchev Thank you for the quick response and resolution! |
Thanks for checking. |
Affects version: 5.3.3
Related to: #26261
I have a controller method that accepts
multipart/form-data
requests with 2 parameters: a file and a@RequestPart String label
.Previously in my tests I was creating a
MockPart
for the label and it was working fine:new MockPart("label", "mainImage".getBytes(UTF_8))
.With the latest changes in 5.3.3 the
MockPart
is converted to a request parameter instead of a multipart boundary and I don't receive anything for theRequestPart
in the controller thus breaking the tests.Why is it necessary to convert MockParts to parameters in a multipart request?
I'm not sure if this is strictly related to the value being a parameter of if there is another underlying issue. I thought that I should receive the value by using either
RequestPart
orRequestParam
just using different converters.The text was updated successfully, but these errors were encountered: