I have been trying to send a multipart request using RestAssured v2.9.0, however it's always throwing errors.
Controller:
@RequestMapping(value = "/my-url", method = RequestMethod.POST, consumes = MULTIPART_FORM_DATA_VALUE)
public void saveSomething(
@RequestParam("form") MultipartFile formFields,
@RequestParam("file") MultipartFile file,
@AuthenticationPrincipal ...
RestAssured call:
given().header(HEADER_NAME, HEADER_VALUE)
.filter(new RequestLoggingFilter())
.multiPart(getMutliPart("{//JSON FORM FIELDS}", "form", "application/json", "blob"))
.multiPart(getMutliPart("Test-Content-In-File", "file", "text/plain", "Test.txt"))
.when()
.post("my-url");
Error message:
org.springframework.web.multipart.support.MissingServletRequestPartException: Required request part 'form' is not present
RestAssured Log:
Request method: POST
Request path: http://localhost:50789/my-url
Proxy: <none>
Request params: <none>
Query params: <none>
Form params: <none>
Path params: <none>
Multiparts: controlName=form, mimeType=application/json, charset=<none>, fileName=blob, content=[123, 345..blah blah]
controlName=file, mimeType=text/plain, charset=<none>, fileName=Test.txt, content==[13, 34..blah blah]
Headers: HEADER=VALUE
Accept=*/*
Content-Type=multipart/form-data
Cookies: <none>
Body: <none>
Apparently, Request params
is blank and that's the reason for the error.
I have also tried sending a MockMultipartFile
inside the .parameters("form", mockMultipartFile)
but no luck.
I have referred to a lot of stuff online including this, but the issue still exists. Any pointers are appreciated.