1

I'm trying to upload pdfs to MinIO using Kotlin Spring. I've written a controller to upload pdfs:

@PostMapping(consumes = [MediaType.MULTIPART_FORM_DATA_VALUE, MediaType.APPLICATION_OCTET_STREAM_VALUE])
    fun createPaper(
        @RequestPart("metadata") paperRequest: PaperRequest,
        @RequestPart("pdf") pdfFile: MultipartFile
    ): ResponseEntity<Paper>

I'm making the following curl request:

$ curl -X POST http://localhost:8082/api/v1/papers -F "metadata={\"title\":\"Example Research Paper\",\"authors\":[\"Jane Smith\",\"John Doe\"],\"ab
stract\":\"This is a test paper abstract\",\"doi\":\"10.1234/test.123\",\"venue\":\"Test Conference 2024\",\"keywords\":[\"testing\",\"research\"]}" -F "[email protected];type=application/pdf" -H "Content-Type: multipart/form-data"

However, I keep getting this response:

{"timestamp":"2025-01-07T09:14:36.910+00:00","status":415,"error":"Unsupported Media Type","path":"/api/v1/papers"}

and here's what the spring logs say:

DefaultHandlerExceptionResolver : Resolved [org.springframework.web.HttpMediaTypeNotSupportedException: Content-Type 'application/octet-stream' is not supported]

Why won't it allow me to upload files?
Things I've tried:

  • added MediaType.APPLICATION_OCTET_STREAM_VALUE to the consumes in the controller
  • added this to the applicatiom.yaml mvc: content-negotiation: media-types: octet-stream: application/octet-stream servlet: multipart: enabled: true max-file-size: 120MB max-request-size: 120MB
  • Tried making the request from Postman, via HTML, and cURL. Any help is appreciated!
2
  • 1
    Remove the consumes element from the @PostMapping, then try again. Commented Jan 7 at 12:38
  • Try my answer. If it helps, I would suggest to add tags: curl and multipartform-data Commented Jan 19 at 16:47

1 Answer 1

1

The problem is not in the your code, the problem is in the curl.
Add the Content-Type of application/json to metadata field

-F "metadata={\"key\": \"value\"};type=application/json"

Your fixed curl:

curl -X POST http://localhost:8082/api/v1/papers \
-F "metadata={\"title\":\"Example Research Paper\",\"authors\":[\"Jane Smith\",\"John Doe\"],\"ab
stract\":\"This is a test paper abstract\",\"doi\":\"10.1234/test.123\",\"venue\":\"Test Conference 2024\",\"keywords\":[\"testing\",\"research\"]};type=application/json" \
-F "[email protected];type=application/pdf"

Also everything should work even without:

  • consumes in @PostMapping
  • -H "Content-Type: multipart/form-data"
  • the configs you have added to application.yaml
Sign up to request clarification or add additional context in comments.

Comments

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.