vendredi 23 octobre 2015

Laravel 5.1 - Force download of a file from the Storage

The recommended way of forcing file downloads is:

return response()->download($pathToFile, $name, $headers);

http://ift.tt/1PGPV6v

But what if I want to force the download using the Storage?

I can get the content:

Storage::disk('local')->get($filepath)

And I can confirm the file exists:

Storage::disk('local')->has($filepath)

But how can I get the complete filepath in a clean way, without hardcoding paths? When you use the Storage method you're using the root from the configuration file and for the cloud providers the root is also optional. So switching from a local disk to a cloud one might break things.

Is there anything similar to this fake method below?

echo Storage::disk('local')->getFullFilepath('/my/folder/my-file.png');
# output: /storage/another/root/my/folder/my-file.png

Also, is there a resource penalty in getting the content first instead of providing a path to the download() method (that uses the Symfony HttpFoundation)? Does it store the entire file in memory first instead of streaming the content directly to the client?



via Chebli Mohamed

Aucun commentaire:

Enregistrer un commentaire