How to add a new R2 bucket on Cloudflare for media files

For storage buckets and domains our preferred provider is cloudflare.

Settings

text
S3_ACCESS_KEY_ID=
S3_SECRET_ACCESS_KEY=
S3_STORAGE_BUCKET_NAME=base
S3_REGION_NAME=
CDN_URL=https://base-cdn.advantch.com

Creating the bucket

On Cloudflare, you will need to configure your R2 bucket to work with your fly.io settings. Follow the steps below:

  1. Navigate to the R2 Storage section in your Cloudflare dashboard and complete the setup.

  2. Click on the name of the bucket you just created. This will take you to the bucket’s settings page.

  3. In the settings page, you will need to input the S3_ACCESS_KEY_ID and S3_SECRET_ACCESS_KEY that you set in your fly.io settings. These are the credentials that Cloudflare will use to access your bucket.

  4. Next, set the S3_STORAGE_BUCKET_NAME to the name of your bucket. This is the same name you used when creating the bucket on Cloudflare.

  5. Lastly, set the CDN_URL to the URL of your Cloudflare CDN. This is the URL that will be used to serve your content from the bucket.

Last note

After you have input all the necessary information, click on the ‘Save’ button to save your settings. Your bucket on Cloudflare is now configured to work with your fly.io settings.

Remember to always keep your S3_ACCESS_KEY_ID and S3_SECRET_ACCESS_KEY secure. These are sensitive information that can give anyone access to your bucket if they are compromised.

With your new bucket set up and configured, you can now start uploading files to it. Any file uploaded to this bucket will be served through your Cloudflare CDN, ensuring fast and secure delivery of your content to your users.

In conclusion, adding a new bucket on Cloudflare and configuring it to work with fly.io is a straightforward process. With the right settings, you can leverage the power of Cloudflare’s CDN to serve your content quickly and securely.