We set out to give WordPress users an easy solution to offload their Media Library to Spaces
We built the Media Library Folders Pro to help WordPress users better manage their Media Library and files with real folders. Many Media Library Folders Pro users rely on the plugin to help them manage especially large Media Libraries - the type that can quickly fill up a server.
These are the types of users who can benefit most from offloading their files to a service like Spaces and serving them either directly, or through a CDN.
In the WordPress space, however, there’s no core functionality to help users offload their Media Library to a service like Spaces. As DigitalOcean users ourselves, we understand the benefit of being able to work within the DigitalOcean platform, which is why we set out to give WordPress users an easy solution to offload their Media Library to DigitalOcean Spaces.
In this post, we’ll detail how we adapted our existing Media Library Folders Pro S3 and Spaces extension to work with DigitalOcean Spaces.
Launched in November 2017, Spaces is DigitalOcean’s object storage service. It has a number of similarities to AWS S3, though it’s notably easier for end users to configure.
In fact, the two are designed to be interoperable, according to the DigitalOcean Spaces API:
${REGION}.digitaloceanspaces.com
and generating a Spaces key to replace your AWS IAM key will allow you to use Spaces in place of S3.To make an existing AWS S3 app compatible with Spaces, you just need to make two tweaks:
Here’s how we did it…
By default, the AWS SDK will attempt to connect to the endpoint of ‘https://s3.amazonaws.com/’. In order to make your app work with Spaces, you need to explicitly change this to connect to Spaces:
try {
$this->s3 = new Aws\S3\S3Client([
'version' => 'latest',
'region' => $region,
'endpoint' => 'https://nyc3.digitaloceanspaces.com',
'credentials' => [
'key' => YOUR_SPACES_ACCESS_KEY_ID,
'secret' => YOUR_SPACES_SECRET_ACCESS_KEY
]
]);
}
In order to let users choose their preferred location, you also need to add a list of Spaces locations like so:
public function get_do_regions() {
$regions = array(
'tor1' => 'Toronto, Ontario — Canada',
'sfo1' => 'San Francisco, California 1',
'sfo2' => 'San Francisco, California 2',
'nyc1' => 'New York City, New York 1',
'nyc2' => 'New York City, New York 2',
'nyc3' => 'New York City, New York 3',
'lon1' => 'London — UK',
'fra1' => 'Frankfurt — Germany',
'ams2' => 'Amsterdam — Holland 2',
'ams3' => 'Amsterdam — Holland 3',
'blr1' => 'Bangalore — India',
'sgp1' => 'Singapore'
);
return $regions;
}
After making the two tweaks above, your S3 application will work with DigitalOcean’s Spaces.
In order to test our modified app’s functionality, we:
Created a new Space at Spaces Generated a Spaces access key and secret Added them to our app where the AWS S3 credentials would have previously gone
And just like that, we were able to successfully connect to Spaces and start uploading and manipulating files with no further changes to our AWS S3 app.
Spaces makes a great alternative to AWS S3 for several reasons:
Because of those benefits, we wanted to give Media Library Folders Pro users the option to take advantage of Spaces. And thanks to Spaces interoperability, we were able to easily get up and running with this new functionality for our users.
This textbox defaults to using Markdown to format your answer.
You can type !ref in this text area to quickly search our full set of tutorials, documentation & marketplace offerings and insert the link!
Have you created an Integration, API Wrapper, Service, or other Tool that helps developers build on DigitalOcean? Help users find it by listing it in Community Tools.
Sign up for Infrastructure as a Newsletter.
Working on improving health and education, reducing inequality, and spurring economic growth? We'd like to help.
Get paid to write technical tutorials and select a tech-focused charity to receive a matching donation.
Does DO Spaces supports some kind of notification? Maybe the S3 one ( https://docs.aws.amazon.com/AmazonS3/latest/dev/NotificationHowTo.html ) or something custom?