Controller中的代码是这样的:
@RequestMapping(path={"/upload_image/"},method={RequestMethod.POST})
@ResponseBody
public String uploadImage(@RequestParam("file") MultipartFile file)
后面是方法主体。
测试时使用postman出现错误:
{
"timestamp": 1583657033784,
"status": 500,
"error": "Internal Server Error",
"exception": "org.springframework.web.multipart.MultipartException",
"message": "The current request is not a multipart request",
"path": "/uploadImage/"
}
查了半天资料翻过头发现在form-data中key忘了填了,填上file之后就好了:
{"msg":"http://127.0.0.1:8080/image?name=44b1d3f64ba148778ab483102c541f90.jpg","code":0}