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’!
Apparently, I have wasted my 1 week trying to work with this plugin.
This plugin works well; everything is served up from R2, but the issue is the way this plugin makes it possible will make your complete WP site crawling to its knees.
Simply because this plugin is using File Stream Wrapper instead of using WordPress-provided hooks and filters.
File stream Wrapper will act like your normal hard drive.
Secondly, it will consume too many API calls that you will end up with a big bill.
Hope someone will find this info useful.