page contents

FormData向后台传文件,后台接收不到报错

Pack 发布于 2020-01-15 16:04
阅读 624
收藏 0

formdata数据:
------WebKitFormBoundaryHw8awRPuYAW8ZCUB
Content-Disposition: form-data; name=“files”; filename=“Martin Garrix.jpg”
Content-Type: image/jpeg

------WebKitFormBoundaryHw8awRPuYAW8ZCUB
Content-Disposition: form-data; name=“files”; filename=“Martin Garrix.jpg”
Content-Type: image/jpeg

------WebKitFormBoundaryHw8awRPuYAW8ZCUB
Content-Disposition: form-data; name=“goods”

{“goodsName”:“wwqe”,“goodsDescribe”:“wqe”,“categoryId”:“608834794213605376”,“goodsStock”:“123”,“goodsPrice”:“23”,“goodsStatus”:“1”}
------WebKitFormBoundaryHw8awRPuYAW8ZCUB–

报错:
error: “Unsupported Media Type”
message: “Content type ‘application/octet-stream’ not supported”
path: “/goods”
status: 415
timestamp: “2019-08-07T19:12:05.631+0000”
trace: "org.springframework.web.HttpMediaTypeNotSupportedException: Content type ‘application/octet-stream’ not supported

Controller方法:
@PostMapping(value = “”)
@ResponseBody
public Result insert(@RequestPart(“goods”) Goods goods, @RequestParam(“files”) MultipartFile[] files) {
logger.info(“添加商品”);

return Result.success("sad", null);

}
我看网上都是这么写的,为什么我的报错了,有大佬能解惑吗

200
Pack
Pack

Content-type:multipart/form-data 用这个

请先 登录 后评论