问题
I'm using spring. I want to implement rest controller to upload file to server. I found a lot examples like this:
public ResponseEntity doSomething(@PathVariable String paramOne, @RequestParam(required = false, name="file") List<MultipartFile> attachments
) throws IOException {
//Some logic here
}
Then I test it with postman, I create a request of type "form-data", add pram name "file", select type file, and select file. And it works ok.
It creates a post request as multipart request. But for some reasons I don't want to use multipart post request. So I want to upload file by select in postman type "binary". So my questions:
Can spring somehow map this kind of request, so I get input file as param in my handler method? (I know that I can get HttpServletRequest and get InputStream from it, but is there a better way?)
With this approach I get only input stream. What is a good way to pass file name?
What are main disadvantages of this approach in general?
来源:https://stackoverflow.com/questions/40000409/spring-rest-upload-file-as-binary