Home > OS >  Current request is not a multipart request with Postman
Current request is not a multipart request with Postman

Time:09-23

I have this class:

@RestController
@RequestMapping("/api/v1")
@Slf4j
public class FileController extends ResourceController {

    private final FileUtils fileUtils;

    public FileController(JwtTokenUtil jwtTokenUtil,
            UserService userService, FileUtils fileUtils) {
        super(jwtTokenUtil, userService);
        this.fileUtils = fileUtils;
    }

    @PostMapping("/uploadFile")
    public void uploadFile( @RequestParam("file") MultipartFile file,
                            @RequestHeader(value = "Authorization") String authHeader) {
...
}

but when I call the endPoint with Postman selecting binary as body I have this error:

"org.springframework.web.multipart.MultipartException: Current request is not a multipart request\n\tat org.springframework.web.method.annotation.RequestParamMethodArgumentResolver.handleMissingValueInternal(RequestParamMethodArgumentResolver.java:210)\n\tat org.springframework.web.method.annotation.RequestParamMethodArgumentResolver.handleMissingValue(RequestParamMethodArgumentResolver.java:193)\n\tat org.springframework.web.method.annotation.AbstractNamedValueMethodArgumentResolver.resolveArgument(AbstractNamedValueMethodArgumentResolver.java:114)\n\tat org.springframework.web.method.support.

CodePudding user response:

Try using Body as "form-data" in Postman. Then in the "KEY" column select file instead of text, set the key as file and select the file to upload. Additionally, make sure that in the Headers tab you don't have any manually added Content-Type. Postman will derive it based on Body tab.

Check here a Postman example

  • Related