简体   繁体   中英

Spring Boot Multipart REST endpoint gives 'Current request is not a multipart request' when called from Postman

Spring Boot Version: 2.1.5.RELEASE. Spring Cloud Version: Greenwich.RELEASE

I have the following endpoint defined in a class annotated @Controller

@PostMapping("/")
@ResponseBody
public OcrResponse submitFile(@RequestParam("file") MultipartFile multipartFile) {
    logger.info("Entering submitFile method");
    //do more stuff......
}

I am testing it using Postman and it was working fine. Yesterday, I decided to update Postman to the latest release (it is probably at least a year since I updated it). Now, when I test it, I get the following error: -

org.springframework.web.multipart.MultipartException: Current request is not a multipart request
    at org.springframework.web.method.annotation.RequestParamMethodArgumentResolver.handleMissingValue(RequestParamMethodArgumentResolver.java:194)
    at org.springframework.web.method.annotation.AbstractNamedValueMethodArgumentResolver.resolveArgument(AbstractNamedValueMethodArgumentResolver.java:113)

This is what my Postman request looks like: -

  1. Headers. These are automatically included by Postman itself, I have added none of my own: -

邮差头

  1. Body (error also displayed): -

邮递员身体和错误

I have seen other posts with a similar error, but these have mostly been resolved by removing the Content-type header from the request, but that didn't work in this case.

I have tried removing, renaming and re-ordering the Postman headers but none of this helped. I have also tried changing the REST endpoint method signature, such as renaming the MultipartFile variable and parameter and using RequestPart instead of RequestParam, but so far nothing has worked. It seems strange that exactly the same request worked on an older version of Postman. I would be extremely grateful for any guidance/suggestions.

Just in case it helps anyone else, I am sharing how I got round this issue....

The problem above occurred when I had an older version of Postman installed and I updated that installed version to the latest via the Settings -> Update menu.

Since then, I have completely uninstalled Postman and installed the latest version from scratch. Now the issue has gone away and I can successfully test my endpoint. A bit bizarre, but at least it has unblocked me.

So my advice to anyone upgrading their Postman installation would be to avoid trying to update an existing installation. Instead, export all your collections, completely uninstall the old version, install the new version from scratch and re-import all your collections.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM