Spring REST Upload file as binary

主宰稳场 提交于 2019-12-10 15:28:29

问题


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:

  1. 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?)

  2. With this approach I get only input stream. What is a good way to pass file name?

  3. What are main disadvantages of this approach in general?

来源:https://stackoverflow.com/questions/40000409/spring-rest-upload-file-as-binary

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!