I am trying to upload a file to the server, so I am trying to use @RequestBody to get the data from the file, but I get an error code 415 when I try to upload the file.
So, I have googled (obtained a solution for downloading a file) and found out that I can not get the file data from the request body. Therefore, I want to know why we cannot access data files from the request body, since the data will be sent to the request body in HTTP requests, so I want to know how the request occurs when the file is downloaded.
My server code before:
@RequestMapping(value = "/upload",headers = "Content-Type=multipart/form-data", method = RequestMethod.POST) @ResponseBody public String upload(@RequestBody MultipartFile file) { }
Decision:
@RequestMapping(value = "/upload",headers = "Content-Type=multipart/form-data", method = RequestMethod.POST) @ResponseBody public String upload(MultipartHttpServletRequest request) { }
spring-mvc file-upload
Labeo
source share