I am new to spring rest and trying to create a REST POST API where the user can send a file to the server.
@RequestMapping(value = "/order", method = RequestMethod.POST)
public String create(@RequestParam("file") MultipartFile file) {
System.out.println("---------INSIDE ORDER----------");
return "file succesfully received!";
}
But I when make a call to this API by uploading a order.txt file and selecting form-data (in postman) I get this error
{
"timestamp": 1474129488458,
"status": 400,
"error": "Bad Request",
"exception": "org.springframework.web.multipart.support.MissingServletRequestPartException",
"message": "Required request part 'file' is not present",
"path": "/order"
}
Problem is not with your code which accepts the request. It is with the request how you are making.
-d is used to pass the data. You have to use -F as shown below
curl -X POST localhost:8080/order -F "[email protected]"
Refer post section of curl manual for more details
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With