본문 바로가기

카테고리 없음

Laravel Download File From Storage



How to use the storage system to generate a file download? Is there a function I can use to get the complete path of file or how to get this working? I would like to use the storage systems functions and not 'hardcode' the mainpath into my app. Laravel Response class has a method called download() and we gonna use this. The file is located in storage/app directory, you can place files wherever you.

I want to access a pdf file from the browser, the file is located in laravel storage folder. I don't want the storage to be public.

I don't want to download it(that I managed to do it). I simply want to have a get route, and to show that file in the browser like: www.test.com/admin/showPDF/123/123_321.pdf.

123 is an id.

If I use:

Laravel Download File From Storage

return the full server path.

thanks.

CosminCosmin

5 Answers

You can read it from the storage folder and then stream the content to the browser and force the browser to download it.

Ivanka TodorovaIvanka Todorova

Quick and dirty, but what you want to do is use the path you grabbed in the response from a controller method (or route closure, your call). Something like:

See https://laravel.com/docs/5.4/responses#file-responses for more information on this, but that's how I'd go about it

pxslippxslip

You have to stream your file in a request. In your controller do the following thing

Laravel Download File From Storage To Computer

This will directly stream your PDF

Desh901Desh901

You can make an symbolink link between storage/app/public and public/storage so you can access your files, by running

More info Here.

Then you can make a route like this to access the files:

So in this case if you save a pdf named 123.pdf in the folder storage/app/public/pdffolder

you have to tweak it a little bit, but i think this can help you.

Leonardo CabréLeonardo Cabré
Yusuf Eka SayoganaYusuf Eka Sayogana

Laravel Download File From Storage Folder

Not the answer you're looking for? Browse other questions tagged laravellaravel-5.2 or ask your own question.