Nuñito Calzada
Nuñito Calzada

Reputation: 2086

Current request is not a multipart request with Postman

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.

Upvotes: 2

Views: 4258

Answers (1)

João Dias
João Dias

Reputation: 17460

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

Upvotes: 3

Related Questions