0
votes

I have used local storage for file storing. I have created table of file, in which title, path, card_id rows stored.

$request->file('file')->storeAs('public/upload',$files->getClientOriginalName());

i.e:passport.png stored at /home/dhruv/MyProject/storage/app/public/upload/passport.png

Above works fine but I'm getting error while downloading file. in controller...

    public function getDownload($file_id)
    {

        $file = File::find($file_id);
        //print_r($file);    
            return response()->download($file->path);
             /*  return response()->download(
                $file->path,
                    $file->name,
                    [],
                    'inline'//attachment
                );*/

    }

I tried many downloading methods but any didn't work fine. I am getting this error.

Symfony\Component\HttpFoundation\File\Exception\FileNotFoundException: The file "/home/dhruv/MyProject/storage/public/upload/passport.png" does not exist in file /home/dhruv/MyProject/vendor/symfony/http-foundation/File/File.php on line 37

I dont know why it is searching at /home/dhruv/MyProject/vendor/symfony/http-foundation/File/File.php since i have inserted correct path.

So suggest any method for downloading ..

1
Please find you image this path "/home/dhruv/MyProject/storage/public/upload/passport.png"Sagar Patel
do you have this /home/dhruv/MyProject/storage/public/upload/passport.png fileSohel0415
Yes,That works fineDhruv Koshiyar
show us your folder structure where this image existsSohel0415
path are different,Sohel0415

1 Answers

0
votes

return response()->download(Storage::get($file->path));

Import this before:
use Illuminate\Support\Facades\Storage;

Laravel Storage

Or try this:
return response()->download(storage_path($file->path));