Laravel 5.6 Storage::download file not found
10,634
Solution was: return Storage::disk('public')->download($file->path);
Author by
darjus
Laravel/Symfony developer. Also codding with JS/Vue, node and GOlang
Updated on June 05, 2022Comments
-
darjus almost 2 years
I'm using Laravel 5.6, filesystems.php config default.
When file is uploaded I have record in my DB with path column where paths is recorded like - posts/p4NbvgcxHFcT10TwbS2UUJrajifPcqpN3i7iSyyk.png
Symlink was created and files stored in public dir.
$path = $file->store('posts', 'public');
This path is recorder to DB, if I want to show e.g. image, I can access it by:
{{ asset('/storage/'.$file->path) }}
But when I try to force download it get exception - FileNotFoundException File not found at path:
File download method:
public function downloadFile($id){ $file = File::find($id); //return Storage::download(storage_path()."/app/public/".$file->path, $file->original_name); //also tried like this return Storage::download(asset('storage/'.$file->path), $file->original_name); }
App running on Windows OS
-
Lukáš Irsák almost 6 yearswhat returns
$file->path
property ? try to dump it in downloadFile method -
brombeer almost 6 years
{{ asset('/storage/'.$file->path) }}
andasset('storage/'.$file->path)
might not be same -
darjus almost 6 yearsdd( asset('/storage/'.$file->path), asset('storage/'.$file->path) ); result is same. $file->path return path like posts/p4NbvgcxHFcT10TwbS2UUJrajifPcqpN3i7iSyyk.png
-
-
darjus almost 6 yearsNope, same error. But storage_path('app/public/'.$file->path) gives correct path to the file. If i write to explorer path returned from this code I can access file, but Storage::download can't see this file.
-
Alexa over 2 yearsGracias tu solución funcionó! Como comentario adicional, public deberá ser cambiado por el repositorio que se esté manejando como aws o digitalocean.