Quantcast
Channel: Active questions tagged rest - Stack Overflow
Viewing all articles
Browse latest Browse all 3641

Spring REST Upload file as binary

$
0
0

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 param name "file", select type file, and select file. And it works ok.

It creates a post request as multipart request. But for some reason, 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?


Viewing all articles
Browse latest Browse all 3641

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>