5

Just a simple question.

Trying to download the storage file but I'm unable to download the file from the storage folder.

Searched on google. Found two ways to download storage files. Tried both but in vain.

return response()->download(storage_path("app\public\uploads\1662531990_Dropshipping.docx"));
return Storage::disk('public')->download("app\public\uploads\1662531990_Dropshipping.docx", "1662531990_Dropshipping");

Yes, the above-given files exist inside the given path. Below is the screenshot of that directory and error screen.

It has something to do with the flysystem hence below are the related packages, I think, as a result of the composer show

league/config                      v1.1.1  Define configuration arrays with strict schemas an...   
league/flysystem                   3.2.1   File storage abstraction for PHP
league/flysystem-aws-s3-v3         3.0.0   AWS S3 filesystem adapter for Flysystem.
league/mime-type-detection         1.11.0  Mime-type detection for Flysystem

enter image description here

enter image description here

Faizan Kamal
  • 1,732
  • 3
  • 27
  • 56
  • Check if [fileinfo](https://www.php.net/manual/en/fileinfo.installation.php) is installed and enabled. It is most of the time but do a `phpinfo()` to be sure. Also make sure the file is readable by the webserver – apokryfos Sep 10 '22 at 13:35
  • 1
    Is symlink to storage/public created? – nikistag Sep 10 '22 at 14:43
  • 1
    Have you solved it? I'm getting the exact same error when trying to download a .zip file with `return Storage::disk('pdf')->download(storage_path('app/pathToThe/'.$zip_file));` – Pathros Oct 03 '22 at 16:30

1 Answers1

0

The easiest way to download the file from storage for Laravel 9 is using the download method as shown in the documentation.

return Storage::download('file.jpg');
 
return Storage::download('file.jpg', $name, $headers);

Below you will find a code example I used to download a pdf:

public function download(Publication $publication){
    //Path from the local storage directory (./storage/app/)
    $path = $publication->file_path;
    
    //Name of the file the user will see
    $slug = Str::slug($publication->title).'.pdf';

    $headers = [
        'Content-Type' => 'application/pdf',
     ];

     return Storage::download($path, $slug, $headers);
}

Hope this helps!