Endpoint is defined as RestController:
@PatchMapping(value = "/users/test", consumes = MediaType.MULTIPART_FORM_DATA_VALUE, produces = MediaType.APPLICATION_JSON_VALUE)
@ResponseStatus(HttpStatus.NO_CONTENT)
public List userTest(
@Parameter(content = @Content(mediaType = MediaType.MULTIPART_FORM_DATA_VALUE))
@RequestPart(value = "file") MultipartFile file) {
System.out.println(file.getContentType());
return operationResourceService.parseFile(file);
}
The endpoint is designed only to print out the content of the CSV file. Since this is Spring Boot 3 there is no need to define any MultipartResolver, because the default resolver now is the StandardServletMultipartResolver.
After request is sent to the backend, exception is thrown:
org.springframework.web.multipart.support.MissingServletRequestPartException: Required part 'file' is not present.
After detail debug found out that this part of the code is throwing this same exception:
if (arg == null && isRequired) {
if (!MultipartResolutionDelegate.isMultipartRequest(servletRequest)) {
throw new MultipartException("Current request is not a multipart request");
}
else {
throw new MissingServletRequestPartException(name); // EXCEPTION
}
}
But main cause is that method resolveMultipartArgument is returning null from some strange reason...
Object mpArg = MultipartResolutionDelegate.resolveMultipartArgument(name, parameter, servletRequest); // Returns null
if (mpArg != MultipartResolutionDelegate.UNRESOLVABLE) {
arg = mpArg; // This is the line where arg is assigned as null
}
0 comments:
Post a Comment
Thanks