spring-boot REST POST API发送文件

krs8888

我刚接触Spring并尝试创建REST POST 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文件并选择表格数据(在邮递员中)调用此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"
}
拉文德拉·德瓦迪加(Ravindra Devadiga)

问题不在于您的接受请求的代码。这是与您的要求如何。

-d用于传递数据。您必须使用-F,如下所示

curl -X POST localhost:8080/order -F "[email protected]"

有关更多详细信息,请参见curl手册的发布部分。

本文收集自互联网,转载请注明来源。

如有侵权,请联系 [email protected] 删除。

编辑于
0

我来说两句

0 条评论
登录 后参与评论

相关文章