Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

mbo's avatar
Level 3

How to setup pleague glide with digital ocean spaces?

Good day

I'm using glide of https://glide.thephpleague.com/ for showing and cashing my images. Till now i saved my images on my webserver. No i want do place them on Digital Ocean spaces.

But i can't get it working.

current setup:

  • imagecontroler where i handle the images.
  • installed league/flysystem-aws-s3-v3

to make it working i should work with: https://flysystem.thephpleague.com/v1/docs/adapter/digitalocean-spaces/

use Aws\S3\S3Client;
use League\Flysystem\AwsS3v3\AwsS3Adapter;
use League\Flysystem\Filesystem;

$client = new S3Client([
    'credentials' => [
        'key'    => 'your-key',
        'secret' => 'your-secret',
    ],
    'region' => 'your-region',
    'version' => 'latest|version',
    'endpoint' => 'https://your-region.digitaloceanspaces.com',
]);

$adapter = new AwsS3Adapter($client, 'your-bucket-name');

$filesystem = new Filesystem($adapter);

this is what my imagecontroller looks like:

<?php

namespace App\Http\Controllers;

use Illuminate\Http\Request;
use Illuminate\Contracts\Filesystem\Filesystem;
use League\Glide\Responses\LaravelResponseFactory;
use League\Glide\ServerFactory;
use App\Http\Requests;


class ImageController extends Controller
{

    /**
     * Display the specified resource.
     *
     * @param  int  $id
     * @return \Illuminate\Http\Response
     */
     public function show(Filesystem $filesystem, $path)
     {
 
        $server = ServerFactory::create([
            'response' => new LaravelResponseFactory(app('request')),
            'source' => 'xx/uploads/images',
            'cache' => 'xx/uploads/cache_images',
            'base_url' => 'img',
        ]);

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

}

my question is:

where to use this extra code for the adapter? And why?

Thanks in advance.

0 likes
3 replies
bobbybouwmann's avatar

As far as I understand, glide isn't really build for this. It's an image manipulation library on the fly. This basically means it needs access to the image. If you first need to fetch the image from digital ocean and then modify it and server it, it's going to be really slow.

Anyway, back to the problem. What exactly is not working? Can you create the server object?

mbo's avatar
mbo
OP
Best Answer
Level 3

Bobby,

thanks for your reaction.

The reason why i use glide is because the package helps me the crop the images to the right dimensions. So i can keep the original in place and create a cached image with the right dimensions.

So my plan is to:

  • save the original on do spaces
  • save the cached images on my webserver

About the last step i'm thinking of putting these on do spaces as well. Don't know what is best.

What do you think about this way of working? Do you suggest a different approach?

About the problem: i got it working with help of this post: https://github.com/thephpleague/glide/issues/100

For people interested:

  • i used the default filestem adjustments
  'do-spaces' => [
            'driver' => 's3',
            'key' => 'xxx',
            'secret' => 'xxx',
            'region' => 'ams3',
            'bucket' => 'xx',
            'endpoint' => 'https://ams3.digitaloceanspaces.com',
        ],

in combination with this in my controllers.

 public function show_listing_230(Filesystem $filesystem, $path)
     {
        $server = ServerFactory::create([
            'response' => new LaravelResponseFactory(app('request')),
            'source' => Storage::disk('do-spaces')->getDriver(),
            'source_path_prefix' => '/xxx/images/listings/230',
            'cache' => Storage::disk('local')->getDriver(),
            'cache_path_prefix'     => '/xxx/images/listings/230/cache_images',
            'base_url' => 'img_listing/230/',
        ]);

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


bobbybouwmann's avatar

Awesome that you got it working!

I would probably cache all my images because that is faster in the end ;) You already use the space and storage is cheap these days, so why not ;)

Please or to participate in this conversation.