2

I have a simple project that works on PDF files. I am trying to code a File Upload Controller. I've tried lots of ways to do this but it keeps giving me this error :

Resolved [org.springframework.web.HttpMediaTypeNotSupportedException: Content type 'multipart/form-data;boundary=----WebKitFormBoundarykuss6O97yqzGx0dG' not supported]

Here is my code:

@PostMapping (value = "/setTemplateContent", consumes = MediaType.APPLICATION_PDF_VALUE)
@ResponseStatus(HttpStatus.OK)
@ApiOperation(value= "Get contract and pdf. Save Pdf in Contract", notes = "Convert pdf to ByteArray")
@ResponseBody
public void setTemplateContent(@RequestParam("file") MultipartFile file)
        throws IOException {
}

I am using Swagger UI to send requests.

Swagger Post Method Image

I've even tried to implement the "Getting Started" example from Spring's official guide website. I cannot see where is my problem. Can you help me to see my problem?

7
  • Are you setting the Content-Type: application/pdf header when sending the request? Commented Jan 14, 2021 at 14:47
  • Well Swagger asks me nothing about the header. You can check my post configs from the Swagger Post Method Image Commented Jan 14, 2021 at 14:48
  • Yeah, I see that. Well, if you're using Swagger Inspector, setting a header is pretty straightforward. If using Swagger UI, you can specify a header in the text specification like this: stackoverflow.com/questions/41180615/… Commented Jan 14, 2021 at 15:35
  • Your request is multipart form data, so it has to use something like @Consumes(MediaType.MULTIPART_FORM_DATA) instead of APPLICATION_PDF_VALUE Commented Jan 14, 2021 at 18:05
  • @Helen Thank you for the edit and advice. I will try your suggestion. Commented Jan 14, 2021 at 18:37

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.