【发布时间】:2020-01-02 13:30:11
【问题描述】:
我使用的是 Spring Boot 版本 = 1.5.2.RELEASE。 当我发送带有 json 对象的多部分文件以在邮递员中上传文件时,它会抛出 415 Unsupported Media Type 异常。
这是我的控制器类。
@RestController
@RequestMapping("/service/promotion/")
public class JobController {
....
....
....
@RequestMapping(value = "/job/test", method = RequestMethod.POST, produces = "application/json", consumes = "multipart/form-data")
public ResponseEntity<Object> createJobTest(@Valid @RequestBody JobRequest jobRequest,
@RequestParam(value = "file", required = false) MultipartFile multiPartFile) throws Exception {
我的 json 请求类。
public class JobRequest {
private String campaignKey;
private String communicationId;
private Integer channelId;
private String templateType;
private String subject;
private String frequencyControl;
private Integer leadsRequested;
private String keywordRelavance;
private String scheduledAt;
private String file;
private String updatedBy;
//getter and setter
}
但是当我从控制器类和邮递员中删除消耗时
@RequestMapping(value = "/job/test", method = RequestMethod.POST, produces = "application/json")
然后调试器进入控制器类,但多部分文件值出现 null 在请求对象中,例如
我在 Google 上搜索了很多,已经发布了很多类似的问题,但没有一个对我有帮助。 请帮我解开这个谜。
谢谢。
【问题讨论】:
-
我也有同样的问题。找到问题了吗?
标签: json spring-boot multipartform-data