小编fue*_*a22的帖子

Spring Boot - 多部分 - 不支持的媒体类型

我想在一个帖子请求中发送一个文件和一个 json 模型。

我的请求映射如下所示:

    @PostMapping("{id}/files")
    public MyOutput create(@PathVariable String id, @RequestPart("request") MyInput input, @RequestPart("file") MultipartFile file) {
    // ...
    }
Run Code Online (Sandbox Code Playgroud)

我收到的错误:

{
    "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"
}
Run Code Online (Sandbox Code Playgroud)

邮递员请求:http : //imgshare.free.fr/uploads/62f4cbf671.jpg

我的网络配置:

    @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); …
Run Code Online (Sandbox Code Playgroud)

java rest spring-boot

4
推荐指数
1
解决办法
1万
查看次数

标签 统计

java ×1

rest ×1

spring-boot ×1