I want to send a file and a json model at one post request.
My Request Mapping looks like that:
@PostMapping("{id}/files")
public MyOutput create(@PathVariable String id, @RequestPart("request") MyInput input, @RequestPart("file") MultipartFile file) {
// ...
}
The error I receive:
{
"timestamp": "Feb 7, 2019, 3:18:50 PM",
"status": 415,
"error": "Unsupported Media Type",
"message": "Content type 'application/octet-stream' not supported",
"trace": "org.springframework.web.HttpMediaTypeNotSupportedException: Content type 'application/octet-stream' not supported...,
"path": "/tests/12345/files"
}
Postman request:
http://imgshare.free.fr/uploads/62f4cbf671.jpg
My WebConfig:
@Override
public void configureMessageConverters(final List<HttpMessageConverter<?>> converters) {
GsonBuilder builder = new GsonBuilder();
Gson gson = builder.setPrettyPrinting().create();
final GsonHttpMessageConverter msgConverter = new GsonHttpMessageConverter();
msgConverter.setGson(gson);
msgConverter.setDefaultCharset(StandardCharsets.UTF_8);
converters.add(msgConverter);
converters.add(new StringHttpMessageConverter());
//
converters.add(new ByteArrayHttpMessageConverter());
converters.add(new FormHttpMessageConverter());
converters.add(new ResourceHttpMessageConverter());
}
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…