r2-upload/SKILL.md

64 lines
1.5 KiB
Markdown

---
name: r2-upload
description: Upload files to Cloudflare R2 via S3-compatible API. Standalone skill and importable package.
---
# R2 Upload
Upload files to Cloudflare R2. Works as a CLI skill and as an importable package for other skills.
## CLI Usage
```bash
bun run upload -- --file=/tmp/report.pdf --key=reports/2024/report.pdf
bun run upload -- --file=/tmp/data.json
bun run upload -- --file=/tmp/image.png --content-type=image/png --dry-run
```
## As Package Dependency
Other skills can import this package:
```json
{ "dependencies": { "@clawd/r2-upload": "file:../r2-upload" } }
```
```ts
import { loadR2Config, uploadToR2, uploadFile } from "@clawd/r2-upload";
const config = loadR2Config();
const url = await uploadToR2(config, "my/key.txt", "content", "text/plain");
const result = await uploadFile(config, "/tmp/file.pdf", "docs/file.pdf");
```
## Config
All R2 config is loaded from `.env.local`:
```
CLOUDFLARE_ACCESS_KEY_ID=xxx
CLOUDFLARE_SECRET_ACCESS_KEY=xxx
CLOUDFLARE_ENDPOINT=https://xxx.r2.cloudflarestorage.com
CLOUDFLARE_BUCKET_NAME=common-static
CLOUDFLARE_PUBLIC_URL=https://static.example.com
```
## CLI Flags
- `--file` (required) local file path to upload
- `--key` R2 object key (default: `uploads/<timestamp>/<filename>`)
- `--content-type` MIME type (default: auto-detected from extension)
- `--dry-run` validate without uploading
## Output
```json
{
"status": "success",
"key": "reports/2024/report.pdf",
"url": "https://static.example.com/reports/2024/report.pdf",
"size": 12345,
"contentType": "application/pdf"
}
```