79334195

Date: 2025-01-06 20:04:37
Score: 1
Natty:
Report link

If we publish it in the public folder, people who have the link can openly view this file. For example: example.com/storage/files/abcd1234.png . Anyone can visit this link and view it.

I was advised to access via url using storage facede for this. not sure if it is the best solution.

Here is a code example.

Route::get('/storage/products/{path}', function ($path) {
        $path = 'products/' . $path;
        if (!Storage::disk('local')->exists($path)) {
            abort(404);
        }
    
        $file = Storage::disk('local')->get($path);
        $mimeType = Storage::disk('local')->mimeType($path);
    
        return Response::make($file, 200)->header("Content-Type", $mimeType);
})
Reasons:
  • Blacklisted phrase (1): this link
  • Long answer (-0.5):
  • Has code block (-0.5):
  • Low reputation (1):
Posted by: Kadir Bay