Can we use multipart and @RequestBody together in spring?

后端 未结 4 1122
醉酒成梦
醉酒成梦 2021-02-20 06:00

I want to create a API which can have parameter as multipart file and JSON object (@RequestBody). Please find following snippet while calling this API. I am getting HTTP 415 Uns

4条回答
  •  庸人自扰
    2021-02-20 06:22

    An example of a post method which receives a json object and a generic file:

    public ResponseEntity postGenerateReport(@RequestPart GenerateReportDTO, generateReportDTO, @RequestPart MultipartFile jxhtmlReport)
    

    For the PostMan setup (or curl or anyother REST test utility) you just have to add form-data request with 2 elements:

    1. Key:generateReportDTO, Value: File with .json extension (and compatible content with the object)
    2. Key:jxhtmlReport, Value: just any file.

    Gl

提交回复
热议问题