🪣 R2
Specify R2 Buckets to add to your environment as follows:
const mf = new Miniflare({  r2Buckets: ["BUCKET1", "BUCKET2"],});For testing, it can be useful to put/get data from R2 storage
outside a worker. You can do this with the getR2Bucket method:
import { Miniflare } from "miniflare";
const mf = new Miniflare({  modules: true,  script: `  export default {    async fetch(request, env, ctx) {      const object = await env.BUCKET.get("count");      const value = parseInt(await object.text()) + 1;      await env.BUCKET.put("count", value.toString());      return new Response(value.toString());    }  }  `,  r2Buckets: ["BUCKET"],});
const bucket = await mf.getR2Bucket("BUCKET");await bucket.put("count", "1");
const res = await mf.dispatchFetch("http://localhost:8787/");console.log(await res.text()); // 2console.log(await (await bucket.get("count")).text()); // 2Was this helpful?
- Resources
 - API
 - New to Cloudflare?
 - Products
 - Sponsorships
 - Open Source
 
- Support
 - Help Center
 - System Status
 - Compliance
 - GDPR
 
- Company
 - cloudflare.com
 - Our team
 - Careers
 
- 2025 Cloudflare, Inc.
 - Privacy Policy
 - Terms of Use
 - Report Security Issues
 - Trademark