Laravel 5.2 – How to access image from storage folder


Laravel provides a powerful filesystem. Using filesystem you can easily upload files and make it private so user cannot download it directly.

But if you want to provide public URL then there is some way to do it.

First option is by creating a symbolic link. create a symbolic link at public/storage which points to the storage/app/public. for more details visit laravel documentation https://laravel.com/docs/5.2/filesystem#retrieving-files, but if you are in shared hosting or in cluster server you can’t do this.

Another way is but not a optimized solution, using route
 Route::get('storage/{filename}', function ($filename)  {  $path = storage_path('public/' . $filename); if (!File::exists($path)) {  abort(404);  } $file = File::get($path);  $type = File::mimeType($path); $response = Response::make($file, 200);  $response->header("Content-Type", $type); return $response;  });

You can now access your files as follow:

http://domain.com/storage/image.jpg

Please Post Your Comments

Your email address will not be published. Required fields are marked *