@0x5b62656e5d/r2-files
v1.1.0
Published
A simple CLI tool to manage Cloudflare R2 buckets
Maintainers
Readme
r2-files
A simple CLI tool to manage Cloudflare R2 buckets
Description
This CLI tool helps manage files from a Cloudflare R2 bucket. It can download, upload, list, and delete files from the specified bucket. It also automatically copies the link to download the file to the clipboard upon successful upload.
Installation
Install via npm
npm install -g @0x5b62656e5d/r2-filesSetup
Cloudflare setup
This tool requires a Cloudflare account, as well as an active Cloudflare R2 plan. API tokens can be created by heading to Cloudflare's R2 Object Storage Overview page, then heading to the Manage API Tokens page.

Create a token that has Object Read and Write permissions, and note down the Access Key ID, Secret Access Key, and the Endpoint URL for S3 clients. Make sure you already have a bucket created to store files.
Environment variables setup
Create a .env file under the following directory: ~/.config/r2-files/.
Configuration template:
R2_ACCESS_KEY_ID=<Your-R2-Access-Key>
R2_SECRET_ACCESS_KEY=<Your-R2-Secret-Access-Key>
R2_ENDPOINT=<Your-R2-Endpoint>
R2_BUCKET=<Your-R2-Bucket-Name>
DOWNLOAD_URL=<Your-R2-Bucket-URL>You can link a custom domain to the bucket for the DOWNLOAD_URL. If you don't own a domain, use the Public Development
URL for DOWNLOAD_URL. Make sure that the URL does not end with a /.
Usage
NAME
r2-files - Manage files for a R2 bucket
COMMANDS:
download <file-key> <download-path> [<download-name>]
Download a file given the file-key and download-path. Specify download-name to customize the downloaded file's name.
upload <file-path> [<desired-file-name>]
Upload a file given the file-path. Specify desired-file-name to customize the uploaded filename in the bucket. Will default to UUID if not desired-file-name is not specified or already exists in the bucket.
delete <object-key>
Delete a file given the file-key.
delete-all -y
Delete all files in the bucket
list
List all the files in the bucketExamples
Downloads somefile.txt into ~/Downlaods/text.txt
r2-files download somefile.txt ~/Downloads/text.txtUploads ~/Downloads/folder/text.txt as text.txt
r2-files upload ~/Downloads/folder/text.txt text.txtDeletes text.txt from the bucket
r2-files delete text.txtDeletes all files from the bucket
r2-files delete-all -yLists all the files from the bucket
r2-files list