我刚接触Spring Rest,正在尝试创建一个REST POST API,在这个API中,用户可以将文件发送到服务器。
@RequestMapping(value = "/order", method = RequestMethod.POST)
public String create(@RequestParam("file") MultipartFile file) {
System.out.println("---------INSIDE ORDER----------");
return "file succesfully received!";
}
但是,当我通过上传 order.txt 文件并选择表单数据 (在 Postman 中) 调用此 API 时,我会收到以下错误:
{
"timestamp": 1474129488458,
"status": 400,
"error": "Bad Request",
"exception": "org.springframework.web.multipart.support.MissingServletRequestPartException",
"message": "Required request part 'file' is not present",
"path": "/order"
}
file
参数的?请发布请求。 - Maroun