May 01. 2019 · by Helge Sverre

How to use Digital Ocean Spaces to store you assets in Craft 3

Sign up or login to your DigitalOcean account.

Create a new "Space", and give it a name, i usually give it the same name as the clients website name, A "Space" is a separate container for your assets. so you can separate files across projects, think of it like a project folder.

Then go to the "API" section in the sidebar and create a new "Spaces access keys", save the Secret and the API Key,

Download and install the DO Spaces plugin.

Install and Enable DO Spaces
# Install it
 composer require vaersaagod/dospaces

# Enable it
php craft install/plugin dospaces
  1. Now go into your Craft CMS control panel
  2. Go to settings
  3. Click on Assets
  4. Create a new volume, give it a handle of "files" this has to be the same as the key in the configuration file below, you can change it to something else if you want.

return [
	// This key should be the same as your volume's "handle"
    'files' => [
        'hasUrls' => true,
        'url' => sprintf("", getenv('SPACES_BUCKET'), getenv('SPACES_REGION')),
        'keyId' => getenv('SPACES_API_KEY'),
        'secret' => getenv('SPACES_SECRET'),
        'endpoint' => getenv('SPACES_ENDPOINT'),
        'region' => getenv('SPACES_REGION'),
        'bucket' => getenv('SPACES_BUCKET'),

Now add the following to your .env file, replace the SPACES_API_KEY, SPACES_SECRET and SPACES_BUCKET keys with the API key and API Secret you got from Digital Ocean, the bucket is the name of your DO Space.

NOTE: I by default use AMS3 as the location of the space, if you don't use AMS3, you have to update the SPACES_ENDPOINT to use the correct subdomain.

## Digital Ocean Spaces Config

You now have setup your Craft CMS site to use Digital Ocean Spaces to store your assets, now all uploaded files will be uploaded to Digital Ocean, no matter if you're in local development, staging or production.