LazyCodet

a

10:13:34 19/4/2024 - 4 views -
Programming

#1 Create a bucket - Cloudflare R2, S3 - Zero to Hero

R2

Cloudflare R2 Storage allows developers to store large amounts of unstructured data without the costly egress bandwidth fees associated with typical cloud storage services.

You can use R2 for multiple scenarios, including but not limited to:

  • Storage for cloud-native applications
  • Cloud storage for web content
  • Storage for podcast episodes
  • Data lakes (analytics and big data)
  • Cloud storage output for large batch processes, such as machine learning model artifacts or data sets

Create a bucket

To create a new R2 bucket from the Cloudflare dashboard:

  1. Log in to the Cloudflare dashboard and select R2.
  2. Select Create bucket.
  3. Enter a name for the bucket and select Create bucket.

Upload your first object

  1. From the R2 page in the dashboard, locate and select your bucket.
  2. Select Upload.
  3. Choose to either drag and drop your file into the upload area or select from computer.

You will receive a confirmation message after a successful upload.

For me, I create a bucket named test and I upload an image 

​Access

​Allow everyone access

I will access my image had been uploaded before

- ​In the bucket, I switch to the Setting tab

- In the Public access section, I will add a custom domain (ex: storage-test.example.com) Image 1 

The "Public access" section
Image 1: The "Public access" section

- It will take time to activate the custom domain (not too long)

Custom domain is active
Image 2: Custom domain is active

- After active like Image 2, I can access my image with the URL in the browser: storage-test.example.com/image.png like Image 3 

View the image in the browser
Image 3: View the image in the browser


​Note: When adding a custom domain in there, an A record with type R2 in the DNS of the domain in Cloudflare will be created like Image 4, and in opposition, when removing the custom domain, the record will be removed

 An A record with type R2 will be created
Image 4: An A record with type R2 will be created

​Developers access
If you does not create a domain for everyone access the bucket, the default, any accessing to your bucket will blocked.

If you only allow acessing for developers who can accesses it, you can enable R2.dev subdomain in the setting

​Note: