Content type 'multipart/form-data;boundary=----…;charset=UTF-8' not supported

后端 未结 5 2295
误落风尘
误落风尘 2021-01-01 21:35

I want to send an object to the controller that has several lists with files and several fields with plain text.

public class ContributionNew

        
5条回答
  •  一整个雨季
    2021-01-01 21:45

    As said dknight @RequestBody means use of JSON or XML data with maps your DTO bean. In case of MultipartFile you can't use JSON data so you can't use @RequestBody. Try with @ModelAttribute annotation.

    Working sample :

    @PostMapping("/promoters")
    @Timed
    public ResponseEntity createPromoter(@ModelAttribute PromoterDTO promoterDTO) throws URISyntaxException { ... }
    

    With PromoterDTO like this :

        public class PromoterDTO implements Serializable {
    
            private Long id; 
    
            private String name;
    
            private String address;
    
            private MultipartFile logo;
        }
    

提交回复
热议问题