laraN
laraN

Reputation: 11

Laravel Glide not finding images at urls with extension

I am using Glide, and followed this video https://vimeo.com/118089742 which basically is a walk-through for the instructions on the official site http://glide.thephpleague.com/

Here is my service provider:

$this->app->singleton('League\Glide\Server', function ($app) {

        return \League\Glide\ServerFactory::create([
                'source' => public_path(),
                'cache' => public_path(),
                'source_path_prefix' => 'images/uploads',
                'cache_path_prefix' => 'images/cache',
                'base_url' => '/img/',
        ]);
    });

And here is my current route:

Route::get('img/{path}', function (League\Glide\Server $server, Illuminate\Http\Request $request) {
    $server->outputImage($request);
});

But I am running into problems. When I go to url.com/img/test.png?h=100, it does not work. When looking at chrome dev tools on the page, I get a 404 for the image (however, the original image DOES appear).

I have found that if I switch my route to the following, and only go to url.com/img/test?h=100 (without the extension), then I get the Glided image that I want:

 Route::get('img/{path}', function (League\Glide\Server $server,  Illuminate\Http\Request $request) {
    $server->outputImage($request->path() . '.png', $request->all());
});

However, if I remove the concatenation of the extension and go with simply:

Route::get('img/{path}', function (League\Glide\Server $server,  Illuminate\Http\Request $request) {
    $server->outputImage($request->path(), $request->all());
});

Then route back to url.com/img/test.png?h=100, it fails again.

Do you see anything wrong with what I'm doing, or is there an explanation for why I can't go directly to the image path (with the extension)?

Upvotes: 1

Views: 2257

Answers (2)

Juukie14
Juukie14

Reputation: 318

I'm having the same problem and tried many things. All url's starting with /img/ are Glide generated images. All in /assets/ are static files. I've given up and changed

location ~* \.(?:jpg|jpeg|gif|png|ico|cur|gz|svg|svgz|mp4|ogg|ogv|webm|htc)$

to

location ~* ^/assets/.*\.(?:jpg|jpeg|gif|png|ico|cur|gz|svg|svgz|mp4|ogg|ogv|webm|htc)$.

Hopefully someone has a good solution for this!

Upvotes: 1

laraN
laraN

Reputation: 11

It was all a caching problem. Don't cache your images via htaccess or nginx before using Glide.

Upvotes: 0

Related Questions