内容类型'multipart/form-data; boundary = ----...; charset = UTF-8'不支持 [英] Content type 'multipart/form-data;boundary=----...;charset=UTF-8' not supported

查看:3211
本文介绍了内容类型'multipart/form-data; boundary = ----...; charset = UTF-8'不支持的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想将一个对象发送到控制器,该对象具有几个带有文件的列表和几个带有纯文本的字段.

I want to send an object to the controller that has several lists with files and several fields with plain text.

public class ContributionNew<T extends MovieInfoDTO> {
    private List<T> elementsToAdd;
    private Map<Long, T> elementsToUpdate;
    private Set<Long> idsToDelete;
    private Set<String> sources;
    private String comment;
}

public class Photo extends MovieInfoDTO {
    private MultipartFile photo;
}

@PostMapping(value = "/{id}/contributions/photos")
@ResponseStatus(HttpStatus.CREATED)
public
ResponseEntity<Void> createPhotoContribution(
        @ApiParam(value = "The movie ID", required = true)
        @PathVariable("id") final Long id,
        @ApiParam(value = "The contribution", required = true)
        @RequestBody @Valid final ContributionNew<Photo> contribution
) {

我正在使用邮递员发送数据.但是,他把我扔了

I am sending data using postman. However, he throws me away

org.springframework.web.HttpMediaTypeNotSupportedException: Content type 'multipart/form-data;boundary=----WebKitFormBoundarywY7ByvgonAjDoaCT;charset=UTF-8' not supported

我应该为此控制器设置什么内容类型,以便发送包含纯文本字段和文件列表的对象?

What should I set the Content-type for this controller so that I can send an object that has fields of plain text and lists with files?

如果我在标题中设置标题

If I set the header in the header

Content-type: multipart/form-data; charset=utf-8

它把我扔进了控制台

org.apache.tomcat.util.http.fileupload.FileUploadException: the request was rejected because no multipart boundary was found

推荐答案

在Postman中,您需要将主体设置为raw类型,然后从下拉列表中选择JSON,我遇到了类似的问题,此问题已解决我的问题.

In Postman, you need to set the body to be of type raw, and from the drop down you can select JSON, I had a similar issue, this fixed my issue.

这篇关于内容类型'multipart/form-data; boundary = ----...; charset = UTF-8'不支持的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆