3
votes

can you please help me to sort out silly issue :( I have uploaded image in laravel lumen under project-root/storage/products but I don't know how to check uploaded image in browser,my storage folder is outside public directory, I've tried

http://192.168.11.102:8000/storage/products/upc_1443002080.jpg
http://192.168.11.102:8000/index.php/storage/products/upc_1443002080.jpg

but I got - Sorry, the page you are looking for could not be found.Can you please help me?

Update As you told, I have created routes like this -

$app->get('products/{filename}', function ($filename) {
$path = storage_path().'/products/'.$filename;

if (file_exists($path)) {
    return Response::download($path);
}});

but when I hit http://192.168.11.102:8000/storage/products/upc_1443002080.jpg it is downloading file instead of showing up in browser. Do you have any idea? I have following codes in Response::download function -

public static function download($file, $name = null, array $headers = [], $disposition = 'attachment')
{
    $response = new BinaryFileResponse($file, 200, $headers, true, $disposition);
    if (! is_null($name)) {
        return $response->setContentDisposition($disposition, $name, str_replace('%', '', Str::ascii($name)));
    }
    return $response;
}
1

1 Answers

1
votes

The files stored within the storage directory are protected. The document root is /public. To view the uploaded items in the browser, you'd need to create a route that accepts the file name and then the controller will fetch that file.