Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Get the content of MultipartFile

I am trying to get the content of MultipartFile, which is obtained through MultipartHttpServletRequest.getFile().

There are 2 functions in MultipartFile:

  • bytes[] getBytes() ()

  • InputStream getInputStream()

What is the most efficient way to get the content? (Which method would you use?)

like image 835
Lydon Ch Avatar asked Sep 02 '25 02:09

Lydon Ch


1 Answers

Only difference is that with getBytes() the data has already been read from the stream, whereas with getInputStream() you will still have to read the data.

What you use depends on what you want to do with the content. If its an image that you just want to write out to disk, then getBytes() would be best, but if it is Text that you want to parse and do something with, then getInputStream() might be better.

like image 145
Robby Pond Avatar answered Sep 04 '25 15:09

Robby Pond