I’ve setup Cloudflare R2 for a project a while back and noticed that there’s not much information on how to offload media to R2. R2 is compatible with Amazon S3 storage, so we can use existing plugins to tackle this for us!
Let’s start with downloading S3-Uploads, from here: https://github.com/humanmade/S3-Uploads
If you’re not familiar with Github, here’s a direct link to the latest release: https://github.com/humanmade/S3-Uploads/archive/refs/heads/master.zip
Up next
- First up, create a Cloudflare R2 Bucket: First up, set up your bucket in Cloudflare’s dashboard. You can find more about this process here.
- Install S3-Uploads: Grab the S3-Uploads plugin using the links above and install and activate it on in your WordPress Dashboard
- Configure S3-Uploads for R2: Edit your wp-config.php with your bucket’s name and Cloudflare credentials. (see below)
- Verify Your Setup: You can login to your server using SSH and run
wp s3-uploads verify
to confirm everything’s in order.
Configure your wp-config file
define( 'S3_UPLOADS_BUCKET', 'your-bucket-name' );
define( 'S3_UPLOADS_KEY', 'your-access-key' );
define( 'S3_UPLOADS_SECRET', 'your-secret-key' );
define( 'S3_UPLOADS_REGION', 'auto' );
define( 'S3_UPLOADS_ENDPOINT', 'https://your-bucket-name.r2.cloudflarestorage.com' );
That’s it! You can now migrate all your media with commands like wp s3-uploads upload-directory /path/to/uploads/ uploads
. The S3-uploads documentation gives more information about available commands.
Happy devvin’!
Leave a Reply