Cannot download file from storage folder in laravel 5.4

Problem is storage folder is not publicly accessible in default. Storage folder is most likely forsave some private files such as users pictures which is not accessible by other users. If you move them to public folder files will be accessible for everyone. I had similar issue with Laravel 5.4 and I did a small go around by writing a route to download files.

Route::get('files/{file_name}', function($file_name = null)
{
    $path = storage_path()."https://stackoverflow.com/".'app'.'/files/'.$file_name;
    if (file_exists($path)) {
        return Response::download($path);
    }
});

Or you can save your files into public folder up to you.

Leave a Comment