Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/oscarprdev/cloudflare_r2_storage
NPM package to manage files on R2 Bucket at Cloudflare
https://github.com/oscarprdev/cloudflare_r2_storage
bucket cloudflare npm npm-package r2
Last synced: 17 days ago
JSON representation
NPM package to manage files on R2 Bucket at Cloudflare
- Host: GitHub
- URL: https://github.com/oscarprdev/cloudflare_r2_storage
- Owner: oscarprdev
- Created: 2024-03-06T11:03:19.000Z (12 months ago)
- Default Branch: main
- Last Pushed: 2024-03-19T14:27:43.000Z (11 months ago)
- Last Synced: 2024-12-01T10:51:33.388Z (3 months ago)
- Topics: bucket, cloudflare, npm, npm-package, r2
- Language: TypeScript
- Homepage: https://www.npmjs.com/package/@oprdev/cloudflare-r2-storage
- Size: 20.5 KB
- Stars: 1
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# Cloudflare R2 storage
A simple way to manage files using Cloudflare R2 storage
## Features
- Upload files
- List files
- Delete files## Documentation
First, start installing the package in your project:
```javascript
npm i @oprdev/cloudflare-r2-storage
```Second, retrieve the variables to connect the package with Cloudflare storage.
> [!IMPORTANT]
> To start using the package you will need from Cloudflare the following variables:
>
> - Cloudflare_access_key_ID
> - Cloudflare_access_key
> - Bucket name
>
> Please check it out the [Cloudflare Documentation](https://developers.cloudflare.com/fundamentals/api/get-started/create-token/)## How it works
> [!TIP]
> Key value is created from Project and Id```javascript
const bucket = new Bucket({
endpoint,
accessKeyId,
secretAccessKey,
bucketName,
});// Upload file
await bucket.uploadFile({
file,
id: 'your-file-id',
contentType: 'image/webp',
project: 'your-project-name',
});// Get file by project
await bucket.getKeysByEntity({
entity: 'your-project-name',
});// Delete file
await bucket.deleteItemByKey({
key: 'your-project-name/your-file-id',
});
```