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!
consumeselement from the@PostMapping, then try again.curlandmultipartform-data