0
votes

This is what i have done to upload my file into in laravel project.

if($request->file()) {
     $fileName = time().'_'.$request->file('imageFile')->getClientOriginalName();
     $filePath = $request->file('imageFile')->storeAs('products', $fileName, 'public');
     $product->featured_image = '/storage/' . $filePath;
 }

public disk

'public' => [
      'driver' => 'local',
      'root' => storage_path('app/public'),
      'url' => env('APP_URL').'/storage',
      'visibility' => 'public',
 ],

The file uploaded in storage folder inside app/public/products but when I try to retrieve my file showing 404 error. Even I have created the symbolic link with the public folder but not working. i don't no why but files are not showing inside the public folder. files are only uploading project level or private folder inside storage folder. how I can access the file through a web browser.

2

2 Answers

1
votes

First you have create symbolic link

php aritsan storage:link

this will create shortcut storage folder in public folder

so you can access url

asset('storage/products/filename')

in your case it you need to change path while storing

  $product->featured_image =  $fileName;

so while accessing

 asset('storage/products/'.$product->featured_image )

ref:https://laravel.com/docs/8.x/filesystem#the-public-disk

0
votes

Per the doc - "To make these files accessible from the web, you should create a symbolic link from public/storage to storage/app/public"

php artisan storage:link

https://laravel.com/docs/8.x/filesystem