An open API service indexing awesome lists of open source software.

https://github.com/sudo-self/bucket-buddy

Access an R2 bucket with a Cloudflare Worker
https://github.com/sudo-self/bucket-buddy

Last synced: 4 months ago
JSON representation

Access an R2 bucket with a Cloudflare Worker

Awesome Lists containing this project

README

          

# Bucket Buddy 🪣

Screenshot 2024-09-21 at 11 40 03 PM

## Overview

Bucket Buddy is a tool that allows users to interact with Cloudflare R2 storage using a simple interface. It includes a server-side worker for handling file uploads, downloads, and management.

### Components

1. **index.js** - [Worker]
2. **index.html** - [R2 Bucket]

## Getting Started

To create your Cloudflare Worker, run the following command:

```bash
npm create cloudflare@latest -- your-worker-name
```

CRUD Operations

PUT: Uploads an object to the bucket.

GET: Retrieves an object from the bucket.

DELETE: Removes an object from the bucket.

LIST: Retrieves a list of objects in the bucket.

[[r2_buckets]]

binding = 'MY_BUCKET'

bucket_name = 'your-bucket-name-here'


Then place a secret in your worker

wrangler secret put MY_BUCKET

YOUR-R2-STORAGE-API-KEY

1. binding in wrangler.toml
2. secret
3. Replace src/index.js with the one from this repo ```index.js```
4. deploy your worker
npm wrangler deploy

open ```bucket_buddy.py``` and append this line with your worker URL

self.api_url = 'https://your-worker.workers.dev'

***make sure your bucket is configured for public access***

### runpython bucket_buddy.py

Screenshot 2024-09-21 at 10 14 05 PM

alternatively upload the index.html to you bucket then access the buddy at https://your-worker.workers.dev/index.html

## coors cross-origin

```[
{
"AllowedOrigins": [
"http://YOUR-BUCKET-NAME",
"https://YOUR-WORKER-NAME"
],
"AllowedMethods": [
"GET",
"PUT",
"POST",
"DELETE"
],
"AllowedHeaders": [
"*"
],
"ExposeHeaders": [
"Content-Length",
"Content-Type"
],
"MaxAgeSeconds": 3600
}
]

```