Skip to content

Commit

Permalink
feat: cloudflare-r2-binding driver (#235)
Browse files Browse the repository at this point in the history
  • Loading branch information
pi0 authored Jul 4, 2023
1 parent 34f14f8 commit 4386798
Show file tree
Hide file tree
Showing 5 changed files with 789 additions and 559 deletions.
29 changes: 29 additions & 0 deletions docs/content/6.drivers/cloudflare-r2-binding.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
# CloudFlare R2 (binding)

::alert
This is an experimental driver! This driver only works in a cloudflare worker environment and cannot be used in other runtime environments such as Node.js (r2-http driver is coming soon)
::

Store data in [Cloudflare R2](https://developers.cloudflare.com/r2/api/workers/workers-api-reference/) buckets and access from worker bindings.

You need to create and assign a R2 bucket. See [R2 Bindings](https://developers.cloudflare.com/r2/api/workers/workers-api-reference/#create-a-binding) for more information.

```js
import { createStorage } from "unstorage";
import cloudflareR2BindingDriver from "unstorage/drivers/cloudflare-r2-binding";

// Using binding name to be picked from globalThis
const storage = createStorage({
driver: cloudflareR2BindingDriver({ binding: "MY_BUCKET" }),
});

// Directly setting binding
const storage = createStorage({
driver: cloudflareR2BindingDriver({ binding: globalThis.MY_BUCKET }),
});
```

**Options:**

- `binding`: Bucket binding or name.
- `base`: Prefix all keys with base.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -133,4 +133,4 @@
}
},
"packageManager": "pnpm@8.6.5"
}
}
Loading

0 comments on commit 4386798

Please sign in to comment.