spring-guides/gs-uploading-files

MultipartFile.transferTo(File) vs. I/O loop

bshields-idatainc opened this issue · 0 comments

Is there any reason for not using the MultipartFile.transferTo(File) method as opposed to running your own I/O loop as in the example?

I get the impression from the Spring docs that by the time you receive control, the file has already been uploaded to a temporary location and the MultipartFile.getBytes() or .getInputStream() actually is pointing to this local file - not to the request input stream. Simply moving this file is much more efficient than reading/writing it, and doesn't require a lot of memory when the file is large.

Also, if my assumption above is incorrect, wouldn't using:
FileCopyUtils(file.getInputStream(), new FileOutputStream(name))
be safer than file.getBytes()?