[英]Multipart form request in java REST API gives FileNotFound exception
[英]Java, Rest API, multipart
我想在数据库中保存一个实体。 该实体具有多个字段和照片(照片我将保存在byte []中)。 我写了RestController
,但是没有用。 设置JSON
格式,我使用邮递员,在form-data
添加一个文件,在原始文件中放置正文并使用JSON
。
@RequestMapping(value = "/upload", method = RequestMethod.POST, consumes = {"multipart/form-data"})
@ResponseBody
public void storeAd(@RequestPart("client") @Valid Client client, @RequestPart("file") @Valid MultipartFile file) throws IOException {
Client myClient = client;
byte[] s = file.getBytes();
int a = s.length;
}
我看到错误:由处理程序执行引起的已解决异常:
org.springframework.web.HttpMediaTypeNotSupportedException:
Content type 'application/json' not supported
邮递员1的要求
您需要在标题部分添加“ Content-Type:application / x-www-form-urlencoded”。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.