Marinus Klasen

Marinus Klasen

  • Development
  • Consultancy
  • Developer Resources
  • Blog
  • Contact

March 11, 2024

Offloading your WordPress Media Library to Cloudflare R2

Marinus Klasen

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

  1. 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.
  2. Install S3-Uploads: Grab the S3-Uploads plugin using the links above and install and activate it on in your WordPress Dashboard
  3. Configure S3-Uploads for R2: Edit your wp-config.php with your bucket’s name and Cloudflare credentials. (see below)
  4. 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’!

About Marinus Klasen

Marinus has been working in software/web development for more than a decade. Since 2020 his attention shifted on sharing knowledge and developing products and tools for sharing knowledge.

Marinus Klasen on Twitter

Looking for a WordPress expert?
Hire top notch developers on Codeable!

Consult an expert

Comments

  1. Erfa says

    January 11, 2025 at 8:56 am

    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.

    Reply

Leave a Reply Cancel reply

Your email address will not be published. Required fields are marked *

Get in touch

Contact me using the details below

Marinus Klasen

Wilhelmina van Pruisenweg 35, 2595 AN Den Haag

marinus@mklasen.com
twitter.com/marinusklasen
linkedin.com/in/marinusklasen

  • GitHub
  • LinkedIn
  • Twitter

Have you read?

  • Elementor Widget UsageMarch 27, 2025
  • Programmatically showing popups with ElementorMarch 25, 2025
  • The Elementor sanitize_settings errorSeptember 12, 2024
  • Announcing.. Wooping Shop Health!June 13, 2024
  • Swiper setup when using wp-scriptsMarch 14, 2024

Copyright © 2025 ยท Marinus Klasen | Webdesign by Team Rood