Sync your WordPress media with DigitalOcean Spaces

Chirill Ceban
3 min readFeb 23, 2018

--

Handling media in WordPress has never been an easy ride, especially when the size of your media library is pretty big and it keeps increasing. In my work I constantly face with such a problem.

A client of mine has a pretty big website with more then 950 000 files in uploads directory, 30% of these files were created in 2017, and a common outgoing traffic is a little bit above 2Tb per month.
It is a popular website here in Moldova, so it should load fast and should be very consistent in loading times.

Traditional way of keeping all these files in an inside WordPress directory obviously isn’t the best, it will not gain any advantage, but only disadvantages: hard to maintain, hard to backup, hard to copy, costly server and etc.

The solution is simple, to migrate all these files to the cloud and sync them each time somebody uploads something.

Thankfully there are many Object Storage providers that can fit the task, I tried some of them: Amazon AWS, OVH and a recent hero DigitalOcean Spaces.

Amazon is great, it is very powerful and very useful, but the pricing is too high, especially traffic situation. There are multiple AWS compatible plugins, that can sync your library to S3 storage. I personally tried two of them, none of which was good enough for different reasons.

OVH is a newbie in cloud storage services, they use OpenStack Swift other then AWS S3 compatible storage engine, so it is hard to find a working plugin solution that can sync files right away. The pricing is good, but the storage itself feels a little bit buggy.

DigitalOcean Spaces was released in public some time ago with a very, very attractive pricing $5 a month for 250Gb of storage and 2Tb of traffic. Also I’ve been their customer for some time already, I love their dashboard and tools, so it was an easy decision to try them out.

As soon as I didn’t like available plugins that can handle sync, I had to create my own, and here it is DigitalOcean Spaces Sync.

DigitalOcean Spaces Sync is a very simple WordPress plugin that does one thing, but does it very well. It simply connects to one hook and one action in your WordPress installation and receives all the data about files being uploaded. It waits until CMS processes the files, generates all the metadata and after that plugin syncs all of them to the storage.

DigitalOcean Spaces Sync settings page

Overall there are three main things that you should know about plugin configuration before using it:

  • Full URL-path to files field is a URL of your Spaces container, it will be used within WordPress Media Library to link you to your files stored in the cloud
  • Store files only in the cloud option changes the basic behavior of the plugin, while unchecked it will not delete file from your server on upload to cloud storage, if checked, it will remove file from the server and only keep it in the cloud.
  • Delete file from cloud storage option handles delete events fired in WordPress Media Library like this, if checked, plugin will remove file from the cloud storage, if unchecked it will keep it there.

What are the advantages of using DigitalOcean Spaces Sync plugin on your WordPress installation:

  • It is easier to maintain the website, to backup, to restore, to migrate
  • It is safer to keep uploaded media in the cloud, as soon as it is pretty hard to backup large amounts of files
  • Faster access and loading times, DigitalOcean Spaces is build specifically to deliver static content

At this moment of time there is one main drawback in this plugin, you have to copy all your data keeping all the folder structure from your server to DigitalOcean Spaces by yourself. You may use CyberDuck for this or rclone on the server, this thing is absolutely up to you.

Don’t forget to replace links to embedded images and media in posts/pages using Better Search Replace plugin.

And of course, backup your database before doing something!

--

--

Chirill Ceban

Full-Stack Developer, Javascript on both sides, Ruby on Rails sometimes.