thephpleague / glide

Wonderfully easy on-demand image manipulation library with an HTTP based API.
http://glide.thephpleague.com
MIT License
2.55k stars 198 forks source link

Could not find the image error in Laravel #359

Open Exoseed opened 1 year ago

Exoseed commented 1 year ago

Hello,

I have a weird issue with Glide on a fresh local Laravel install (PHP 8.1.13 / Laravel 9.44.0). I followed the documentation to the letter, my route looks like this:

Route::get('/img/{path}', [ImageController::class, 'show'])->where('path', '.*');

I have an ImageController that looks like this:

namespace App\Http\Controllers;

use Illuminate\Contracts\Filesystem\Filesystem;
use League\Glide\Responses\LaravelResponseFactory;
use League\Glide\ServerFactory;

class ImageController extends Controller
{
    public function show(Filesystem $filesystem, $path)
    {
        $server = ServerFactory::create([
            'response' => new LaravelResponseFactory(app('request')),
            'source' => $filesystem->getDriver(),
            'cache' => $filesystem->getDriver(),
            'cache_path_prefix' => '.cache',
        ]);

        return $server->getImageResponse($path, request()->all());
    }
}

But when I try to access an image through the correct path, it gives me a "Could not find the image storage/images/portrait-rose.jpg." error.

Url is: http://localhost:8000/img/storage/images/portrait-rose.jpg

And if I try to access http://localhost:8000/storage/images/portrait-rose.jpg the image definitely shows up. What could be the issue there?

Thanks in advance.