Storage::put vs Storage::putFile*

Published 3 months ago by CD_Rocket

What is the practical difference between these methods?

Docs said that put() store raw file contents on a disk (like file_put_contents?), and putFile() - putFileAs() will manage automatically the streams.

Using streams is greatly recommended when dealing with large files.

I don't know what "Automatic Streaming" means.



Let's take a look at the source code.

public function put($path, $contents, $lock = false)
     return file_put_contents($path, $contents, $lock ? LOCK_EX : 0);
 * Store the uploaded file on the disk.
 * @param  string  $path
 * @param  \Illuminate\Http\File|\Illuminate\Http\UploadedFile  $file
 * @param  array  $options
 * @return string|false
public function putFile($path, $file, $options = [])
     return $this->putFileAs($path, $file, $file->hashName(), $options);

put does indeed only use file_put_contents. putFile on the other hand is used to save on the disk a file that has been uploaded (Http Request).



So "Automatic Streaming" means just that that will be used an instance of UploadedFile or File (so the direct input) instead of raw data? Why is this better for large files?

Please sign in or create an account to participate in this conversation.