In this episode, we walk through how to use DigitalOcean Spaces with a Laravel application. The cool thing is, since DigitalOcean Spaces uses the same API as Amazon S3, you can easily set it up using Laravel's built-in Flysystem S3 driver.
We start off by creating a new Space in the DigitalOcean dashboard, picking a name (after a little trial-and-error with names that aren't already taken) and setting the region. We also make the space private so files are only accessible with our keys.
Next, we head into a fresh Laravel project and look at the config/filesystems.php
file. Here, we duplicate the existing S3 disk setup and adjust the config for our new Space: updating the key, secret, region, bucket name, and most importantly, adding the correct endpoint for DigitalOcean. We generate and copy over our access keys from DigitalOcean's API section.
With the config ready, we demo uploading a file using Laravel's Storage facade. We drop in a short snippet to create a test file and upload it to the Space. After installing the Flysystem AWS package, we refresh the browser to make sure everything works, then check the DigitalOcean dashboard—our file is there!
By the end of this snippet, you've seen just how simple it is to get DigitalOcean Spaces wired up with Laravel—almost plug-and-play if you're already familiar with S3 in Laravel.