Using Digital Ocean Spaces with Filament
This quick tutorial will help you use Filament with Digital Ocean Spaces.
Start by creating a new Space, or you can use an existing one if one is already configured. Next, go to the Settings tab for your Space and locate the CORS Configurations section. Click to add a new configuration and remove the restrictions:
Next, go to the Applications & API page and scroll to the Spaces access keys section. Generate a new key, then copy the Key and Secret.
Now, let's configure Laravel and Filament.
Laravel 8+ comes with AWS s3 driver support out of the box, but if you do not have the driver install it with composer:
composer require league/flysystem-aws-s3-v3
Next, open your config/filesystems.php
file and create a new disk:
"digitalocean" => [ "driver" => "s3", "key" => "[KEY]", "secret" => "[SECRET]", "endpoint" => "https://[REGION].digitaloceanspaces.com", "region" => "[REGION]", // ex. nyc3 "bucket" => "[NAME]", // the unique name you gave your Space "root" => "[FOLDER]", // optional folder "url" => "[EDGE OR CDN ENDPOINT]", // ex: https://[NAME].[REGION].cdn.digitaloceanspaces.com, or https://cdn.yourdomain.com if you setup a custom subdomain "visibility" => "public", // set visibility to private or public],
To set digitalocean
as the default disk for your application, update your env file:
FILESYSTEM_DISK=digitaloceanFILAMENT_FILESYSTEM_DRIVER=digitalocean
Et voila!
A while ago, from docs:
The
FILAMENT_FILESYSTEM_DRIVER
.env variable has been renamed toFILAMENT_FILESYSTEM_DISK
. This is to make it more consistent with Laravel, as Laravel v9 introduced this change as well. Please ensure that you update your .env files accordingly, and don't forget production!