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}
本文详细记录了一次使用Spring框架上传图片时遇到的问题及解决过程。主要问题是在使用Postman进行POST请求时,出现“当前请求不是multipart类型”的错误。通过检查并修正form-data中的key名称为'file',成功解决了问题。
8497

被折叠的 条评论
为什么被折叠?



