I have @Controllerwith a method with a signature like this:
@PostMapping
@ResponseBody
public ResponseEntity<Result> uploadFileAndReturnJson(@RequestParam("file") MultipartFile file) {}
I want to build a multi-page request without physically creating any file. I tried to do it like this:
private MultiPartSpecification getMultiPart() {
return new MultiPartSpecBuilder("111,222")
.mimeType(MimeTypeUtils.MULTIPART_FORM_DATA.toString())
.controlName("file")
.fileName("file")
.build();
}
Response response = RestAssured.given(this.spec)
.auth().basic("admin", "admin")
.multiPart(getMultiPart())
.when().post(URL);
Sorry, I got the answer:
The required request fragment 'file' is missing
I tried looking at RestAssured unit tests, and it seems like I'm doing it right. If I try to pass byte [] or InputStream instead of String, an exception is thrown:
Unable to retry the request with a non-repeating request object.
Thanks for the help.
source
share