towsifkafi/d1bin
Cloudflare Worker that uses a D1 database to store and retrieve paste-like text or binary data.
d1bin
A simple Cloudflare Worker that stores and retrieves data using a Cloudflare D1 database, inspired by lucko/bytebin but built for a serverless architecture. This project was created to run lucko/paste on Cloudflare's serverless workers.
It supports storing binary data, though it is not ideal for large binaries due to the SQL-based D1 database. It is well suited for storing paste-like text data.
Getting Started
Clone the repository and use wrangler to run the project locally.
git clone https://github.com/towsifkafi/d1bin.git
cd d1binCreate a D1 database.
wrangler d1 database create <database_name>
wrangler d1 execute <database_name> --file=./schema.sql # run only onceYou will have to configure the wrangler.jsonc file with your D1 database details. Then you can start the local development server:
wrangler devTo run on a deployed D1 database:
wrangler dev --remoteTo deploy the worker to Cloudflare:
wrangler d1 execute <database_name> --file=./schema.sql # run only once
wrangler deployUsage
Read
GET /{key}(e.g.,/a1b2c3d): Returns content as-is. Client can use encoding (e.g., gzip) during upload.
Write
POST /post: Send content in body. OptionalContent-Type(e.g.,application/json) andUser-Agentheaders. Compress with gzip and setContent-Encoding: gzipfor performance (Optional). Returns unique key inLocationheader and JSON body (e.g.,{"key": "a1b2c3d"}).