Multipart File upload Spring Boot

前端 未结 6 849
栀梦
栀梦 2020-11-29 23:48

Im using Spring Boot and want to use a Controller to receive a multipart file upload. When sending the file I keep getting the error 415 unsupported content type

6条回答
  •  时光说笑
    2020-11-30 00:31

    In Controller, your method should be;

    @RequestMapping(value = "/upload", method = RequestMethod.POST)
        public ResponseEntity uploadAttachment(@RequestParam("file") MultipartFile file, HttpServletRequest request) {
    ....
    

    Further, you need to update application.yml (or application.properties) to support maximum file size and request size.

    spring:
        http:
            multipart:
                max-file-size: 5MB
                max-request-size: 20MB
    

提交回复
热议问题