I need to receive a csv file on the request and process it.
@PostMapping(value = "/csv", consumes = "text/csv")
public ViewObject postCsv(@RequestBody InputStream request){
// do stuff
}
But when I execute:
curl -X POST -H 'Content-Type: text/csv' -d @input.csv http://localhost:8080/csv
This is what shows up on my console:
Resolved [org.springframework.web.HttpMediaTypeNotSupportedException: Content type 'text/csv;charset=UTF-8' not supported]
Spring is saying my request is invalid before anything else.
So, the question is: How to properly receive this csv?
As someone mentioned in comments, one approach is to implement your own HttpMessageConverter - there are examples of varying quality available on the web.
Another option if you already have some code for parsing CSVs using Spring's org.springframework.core.io.Resource
classes is to change your method signature as follows to use Spring's built in ResourceHttpMessageConverter
:
@PostMapping(path = "/csv", consumes = "application/octet-stream")
public ViewObject postCsv(@RequestBody Resource resource){
// do stuff
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With