You might know it's possible to use Amazon S3 for your Asset Containers, but it's also very simple to use DigitalOcean Spaces.
Since Digital Ocean Spaces is compatible with the Amazon S3 API, you can use the s3
flysystem driver, but with Digital Ocean credentials.
Install
First, install the AWS Flysystem adapter:
composer require league/flysystem-aws-s3-v3
Configure a filesystem
Add a filesystem to config/filesystems.php
, and make sure to use the s3
driver.
'do_spaces' => [ 'driver' => 's3', 'key' => env('DO_SPACES_KEY'), 'secret' => env('DO_SPACES_SECRET'), 'endpoint' => env('DO_SPACES_ENDPOINT'), 'region' => env('DO_SPACES_REGION'), 'bucket' => env('DO_SPACES_BUCKET'), 'root' => env('DO_SPACES_ROOT'), 'url' => env('DO_SPACES_URL'), 'visibility' => 'public', // Set this public so the files uploaded are available publically.],
DO_SPACES_KEY=DO_SPACES_SECRET=DO_SPACES_ENDPOINT=DO_SPACES_REGION=DO_SPACES_BUCKET=DO_SPACES_ROOT=DO_SPACES_URL=
- The
key
andsecret
can be generated in the "API" section of your dashboard. - You can find the
endpoint
in the Space's settings. It'll look something likehttps://nyc3.digitaloceanspaces.com
. - The
region
will be in the endpoint. e.g.nyc3
- The
bucket
will be the name of your space. e.g.myspace
- You only need to set the
root
if you want this disk to be a subfolder of your space. This is fairly uncommon. - The
url
will be in the header of the file browser, or in list of your spaces. It'll look something likehttps://myspace.nyc3.digitaloceanspaces.com
- If you've enabled the CDN, it's possible you'd have a non-Digital Ocean
url
. Look for the "edge" URL.
Link to the asset container
Create a new Asset Container using this do_spaces
as a Disk. You can do this via the CP or add a handle.yaml
file to content/assets
:
title: "MySpace"disk: do_spaces
If you're having performance issues with S3 containers in the Control Panel, check out these optimization tips.