Question

The PHP League Flysystem for "Spaces" object storage

Posted September 4, 2017 9.3k views
PHP PHP Frameworks

I am trying to use https://github.com/thephpleague/flysystem-aws-s3-v3 adapter for use with digital ocean spaces as the storage provider as the documentation suggests the api matches amazon s3

Has anyone managed to get flysystem working in any form with digital ocean spaces? I cant seem to work out how to override the base url, the rest of the credentials seem to be passed through.

2 comments
  •    's3' => [
                'driver' => 's3',
                'key' => env('AWS_KEY'),    ===> I found this
                'secret' => env('AWS_SECRET'),  but ?
                'region' => env('AWS_REGION'), but ?
                'bucket' => env('AWS_BUCKET'), but ?
            ],
    

    Can you please help me with the configs

    with Thanks

    edited by asb
  • Of course! first of all from your digital ocean dashboard go to the api tab. Then look at your token/keys, specifically the spaces access keys. When you create a new key or regenerate one you will see the secret, you MUST take note as that is the only time you will see it (without regenerating again invalidating any apps attached). So now you have the key (AWSKEY in .env) and the secret (AWSSECRET). At the moment the only region available is NYC3 so it just set AWSREGION to NY3. When you created the space you will have called it something, whatever you called the space this will be the bucket name set AWSBUCKET to the name of the space. Finally the url was AWS_URL=https://nyc3.digitaloceanspaces.com.

    Set all of these in your .env and then add an entry in your filesystems.php as below

    'DO' => [
        'driver' => 's3',
        'key' => env('AWS_KEY'),
        'secret' => env('AWS_SECRET'),
        'region' => env('AWS_REGION'),
        'bucket' => env('AWS_BUCKET'),
        'endpoint' => env('AWS_URL')
    ],
    

    You can then use the storage facade as follows

    $disk = Storage::disk(‘DO’);
    $content = filegetcontents($file);
    $this->storage->put($filePath, $content , 'public’);

    Where file is a posted file from a form.

These answers are provided by our Community. If you find them useful, show some love by clicking the heart. If you run into issues leave a comment, or add your own answer to help others.

3 answers

This was actually very simple simply set the ‘endpoint’ in your filesystem config to the FQDN of DO spaces eg. in filesytems.php

    'DO' => [
        'driver' => 's3',
        'key' => env('AWS_KEY'),
        'secret' => env('AWS_SECRET'),
        'region' => env('AWS_REGION'),
        'bucket' => env('AWS_BUCKET'),
        'endpoint' => env('AWS_URL')
    ],

and in your .env

AWS_URL=https://nyc3.digitaloceanspaces.com

I’ve set the visibility to public. But it doesn’t work. Can anyone help me?

'spaces' => [
            'driver' => 's3',
            'key' => 'your-key',
            'secret' => 'your-secret',
            'region' => 'your-region',
            'bucket' => 'your-bucket',
            'visibility' => 'public',
],

I get the following error: class Storage not found.. Where does this class come from?

Submit an Answer