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

We Are Going To Discuss About Content type ‘multipart/form-data;boundary=—-…;charset=UTF-8’ not supported. So lets Start this Java Article.

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

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

    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.

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

    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.

Solution 1

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<PromoterDTO> 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;
    }

Original Author uncleBounty Of This Content

Solution 2

In Postman, you need to set the body to be of type raw, and from the drop down you can select JSON, I had a similar issue, this fixed my issue.

view screen here

Original Author plue Of This Content

Solution 3

Instead of @RequestBody, use @RequestParam!

Original Author Shadab Reza Of This Content

Solution 4

use @ModelAttribute instead of @ResponseBody as this takes up data in key value pairs and the later is used for an object like, json.
While hitting the api simply pass the multipart type and json key value pairs of the object. It works fine!

stack overflow question on this

Original Author tushar Of This Content

Conclusion

So This is all About This Tutorial. Hope This Tutorial Helped You. Thank You.

Also Read,

Siddharth

I am an Information Technology Engineer. I have Completed my MCA And I have 4 Year Plus Experience, I am a web developer with knowledge of multiple back-end platforms Like PHP, Node.js, Python and frontend JavaScript frameworks Like Angular, React, and Vue.

Leave a Comment