spring-guides / gs-uploading-files

Uploading Files :: Learn how to build a Spring application that accepts multi-part file uploads.

Home Page:http://spring.io/guides/gs/uploading-files/

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

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

bshields-idatainc opened this issue · 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()?