spring-guides / gs-uploading-files

Uploading Files :: Learn how to build a Spring application that accepts multi-part file uploads.
http://spring.io/guides/gs/uploading-files/
Apache License 2.0
469 stars 503 forks source link

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

Closed bshields-idatainc closed 8 years ago

bshields-idatainc commented 8 years ago

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()?