<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:dc="http://purl.org/dc/elements/1.1/">
  <channel>
    <title>DEV Community: zainarsady</title>
    <description>The latest articles on DEV Community by zainarsady (@zaindev403).</description>
    <link>https://dev.to/zaindev403</link>
    <image>
      <url>https://media2.dev.to/dynamic/image/width=90,height=90,fit=cover,gravity=auto,format=auto/https:%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Fuser%2Fprofile_image%2F4081726%2Fe3e5a5ea-af0f-46cd-a842-f19ee743fb76.png</url>
      <title>DEV Community: zainarsady</title>
      <link>https://dev.to/zaindev403</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/zaindev403"/>
    <language>en</language>
    <item>
      <title>Creating a Cloudflare R2 Bucket</title>
      <dc:creator>zainarsady</dc:creator>
      <pubDate>Tue, 18 Aug 2026 23:29:46 +0000</pubDate>
      <link>https://dev.to/zaindev403/creating-a-cloudflare-r2-bucket-2g0n</link>
      <guid>https://dev.to/zaindev403/creating-a-cloudflare-r2-bucket-2g0n</guid>
      <description>&lt;h3&gt;
  
  
  Good day everyone!!
&lt;/h3&gt;

&lt;p&gt;In my first ever post at dev.to we will discuss about the functionality of &lt;em&gt;Cloudflare R2 bucket&lt;/em&gt;.&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;This post aims to help people set up, configure r2 bucket and upload files on R2 bucket. &lt;/p&gt;
&lt;/blockquote&gt;

&lt;h2&gt;
  
  
  Why do you need an R2 bucket in the first place?
&lt;/h2&gt;

&lt;p&gt;First we need to specify the problem. For most developer, problem with side projects or small projects are the that resources are really scarce. Imagine you have created the perfect system but now you can't store any image from user because you have run out of memory on the server you pay $6.99 every month. &lt;strong&gt;That's where R2 bucket or R2 file storage comes in.&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Let's get right into it, for this tutorial I will mainly refer to this &lt;a href="https://developers.cloudflare.com/r2/get-started/workers-api/" rel="noopener noreferrer"&gt;cloudflare documentation&lt;/a&gt;. &lt;/p&gt;

&lt;h3&gt;
  
  
  Step 0: create Cloudflare account
&lt;/h3&gt;

&lt;ol&gt;
&lt;li&gt;&lt;p&gt;Go to this &lt;a href="https://dash.cloudflare.com/" rel="noopener noreferrer"&gt;link to cloudflare dashboard&lt;/a&gt; and sign up or log in into your account. &lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Go to homepage and click on storage &amp;amp; databases. It should show R2 Object Storage option, let's click that.&lt;/p&gt;&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2Fag2zd1sqkk9kqotcznu3.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2Fag2zd1sqkk9kqotcznu3.png" alt="Click on R2 Object Storage" width="800" height="350"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h3&gt;
  
  
  Step 1: Creating a Bucket
&lt;/h3&gt;

&lt;ul&gt;
&lt;li&gt;Make sure that you're at &lt;a href="https://dash.cloudflare.com/?to=/:account/r2/overview" rel="noopener noreferrer"&gt;overview&lt;/a&gt;. Click "Create a Bucket" on the right hand side of the page. You should be in this page:&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2Ffdxcrsel0n1dymvtqfd0.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2Ffdxcrsel0n1dymvtqfd0.png" alt="Creating Bucket" width="799" height="270"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Type in the bucket name of your liking, the location, and the default storage class. And press Create Bucket, now your bucket is ready to be configured!&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;One thing to understand is that there are 4 ways to access an R2 Bucket:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;Workers API (the one we will use in this tutorial) : built using an application on Cloudflare Workers that need to read and write from R2&lt;/li&gt;
&lt;li&gt;S3 : uses S3-compatible SDKs to interact with R2 mostly in existing applications&lt;/li&gt;
&lt;li&gt;CLI tools: Upload, download, or manage object from the terminal&lt;/li&gt;
&lt;li&gt;Dashboard: Dashboard. On the browser.&lt;/li&gt;
&lt;/ol&gt;

&lt;h3&gt;
  
  
  Step 2: Setting up Bucket and Worker
&lt;/h3&gt;

&lt;ul&gt;
&lt;li&gt;&lt;p&gt;Open up any text editor or IDE and open an empty folder.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Go to the terminal and type in this:&lt;br&gt;
&lt;code&gt;npm create cloudflare@latest -- r2-worker&lt;/code&gt;&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;If prompted to install a new package press y and choose javascript for language. You can get away with the default option for each options but you can also follow these steps showed in images for guidance.&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2Fg40fvyks8u4uijibd7w0.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2Fg40fvyks8u4uijibd7w0.png" alt="HelloWorld" width="644" height="300"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2Fidwo0pwzpnj9oos5kbpb.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2Fidwo0pwzpnj9oos5kbpb.png" alt="worker api" width="636" height="300"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;p&gt;Choose "no" for deploy as we will deploy after we have done setting up &lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Once done with the prompts, change directory to your r2-worker &lt;code&gt;cd r2-worker&lt;/code&gt;&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Open your wrangler.jsonc and it should look like the image below&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2Fvizrih365ln7b1hz9om1.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2Fvizrih365ln7b1hz9om1.png" alt="my wrangler.jsonc" width="799" height="328"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;and put this code at the arrow in the image&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;{
  "r2_buckets": [
    {
      "binding": "MY_BUCKET",
      "bucket_name": "my-bucket"
    }
  ]
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;em&gt;don't forget a comma before putting above code&lt;/em&gt;&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;note that binding here can be named anything but bucket_name must be same as your bucket name&lt;/p&gt;
&lt;/blockquote&gt;

&lt;h3&gt;
  
  
  Step 3: Testing the Bucket
&lt;/h3&gt;

&lt;p&gt;If you have done until here, congratulation you are considered done because now all we have to do is testing.  &lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;We will test in local first, write &lt;code&gt;npx wrangler dev&lt;/code&gt; into your terminal.
It might take some time but once successful it would show this &lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2Fhwr5yparpcp5hxctzljk.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2Fhwr5yparpcp5hxctzljk.png" alt="local development" width="798" height="185"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Now let's test!&lt;/strong&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Open a different terminal, and type in these curl commands.
&lt;/li&gt;
&lt;/ul&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;# Store an object
curl -X PUT http://localhost:8787/my-file.txt -d 'Hello, R2!'

# Retrieve the object
curl http://localhost:8787/my-file.txt
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;ul&gt;
&lt;li&gt;You have successfully store and retrieved a file from your bucket!&lt;/li&gt;
&lt;/ul&gt;

&lt;h3&gt;
  
  
  Step 4: Deployment of worker
&lt;/h3&gt;

&lt;ul&gt;
&lt;li&gt;&lt;p&gt;Type &lt;code&gt;npx wrangler deploy&lt;/code&gt; into your terminal&lt;br&gt;
This will redirect you to browser for you to grant permission.&lt;br&gt;
You must authorize wrangler in order for this application to work. &lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;After deploying, wrangler will output your worker's URL in the terminal. It's usually in this form &lt;code&gt;https://r2-worker.&amp;lt;YOUR_SUBDOMAIN&amp;gt;.workers.dev&lt;/code&gt;. Now you can test storing and retrieving using this link. &lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Just like how we tested it:&lt;br&gt;
&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;# Store an object
curl -X PUT https://r2-worker.&amp;lt;YOUR_SUBDOMAIN&amp;gt;.workers.dev/my-file.txt -d 'Hello, R2!'

# Retrieve the object
curl https://r2-worker.&amp;lt;YOUR_SUBDOMAIN&amp;gt;.workers.dev/my-file.txt
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h3&gt;
  
  
  After words
&lt;/h3&gt;

&lt;p&gt;R2 Bucket has been my first step to the system design endeavor and has improved me as a programmer in the way of thinking as a architecture rather than just a coder. In this world of AI, I believe a good programmer is the one who can make decisions, compare trade-offs and be confident in their production code. &lt;/p&gt;

&lt;p&gt;I hope this post was helpful, this technology can be used in tons of situations and will definitely amplifies the potential of your side projects. &lt;/p&gt;

&lt;p&gt;Thank you for reading. I am open for any feed backs or comments to improve my article writing. Until we meet again!&lt;/p&gt;

</description>
      <category>backend</category>
      <category>r2</category>
      <category>systemdesign</category>
    </item>
  </channel>
</rss>
