davila7/claude-code-templates / cli-tool/components/skills/development/cloudflare-deploy
cloudflare-deploy
FlaggedDeploy applications and infrastructure to Cloudflare using Workers, Pages, and related platform services. Use when the user asks to deploy, host, publish, or set up a project on Cloudflare.
references/r2/gotchas.md
View on GitHub# R2 Gotchas & Troubleshooting
## List Truncation
```typescript
// ❌ WRONG: Don't compare object count when using include
while (listed.objects.length < options.limit) { ... }
// ✅ CORRECT: Always use truncated property
while (listed.truncated) {
const next = await env.MY_BUCKET.list({ cursor: listed.cursor });
// ...
}
```
**Reason:** `include` with metadata may return fewer objects per page to fit metadata.
## ETag Format
```typescript
// ❌ WRONG: Using etag (unquoted) in headers
headers.set('etag', object.etag); // Missing quotes
// ✅ CORRECT: Use httpEtag (quoted)
headers.set('etag', object.httpEtag);
```
## Checksum Limits
Only ONE checksum algorithm allowed per PUT:
```typescript
// ❌ WRONG: Multiple checksums
await env.MY_BUCKET.put(key, data, { md5: hash1, sha256: hash2 }); // Error
// ✅ CORRECT: Pick one
await env.MY_BUCKET.put(key, data, { sha256: hash });
```
## Multipart Requirements
- All parts must be uniform size (except last part)
- Part numbers start at 1 (not 0)
- Uncompleted uploads auto-abort after 7 days
- `resumeMultipartUpload` doesn't validate uploadId existence
## Conditional Operations
```typescript
// Precondition failure returns object WITHOUT body
const object = await env.MY_BUCKET.get(key, {
onlyIf: { etagMatches: '"wrong"' }
});
// Check for body, not just null
if (!object) return new Response('Not found', { status: 404 });
if (!object.body) return new Response(null, { status: 304 }); // Precondition failed
```
## Key Validation
```typescript
// ❌ DANGEROUS: Path traversal
const key = url.pathname.slice(1); // Could be ../../../etc/passwd
await env.MY_BUCKET.get(key);
// ✅ SAFE: Validate keys
if (!key || key.includes('..') || key.startsWith('/')) {
return new Response('Invalid key', { status: 400 });
}
```
## Storage Class Pitfalls
- InfrequentAccess: 30-day minimum billing (even if deleted early)
- Can't transition IA → Standard via lifecycle (use S3 CopyObject)
- Retrieval fees apply for IA reads
## Stream Length Requirement
```typescript
// ❌ WRONG: Streaming unknown length fails silently
const response = await fetch(url);
await env.MY_BUCKET.put(key, response.body); // May fail without error
// ✅ CORRECT: Buffer or use Content-Length
const data = await response.arrayBuffer();
await env.MY_BUCKET.put(key, data);
// OR: Pass Content-Length if known
const object = await env.MY_BUCKET.put(key, request.body, {
httpMetadata: {
contentLength: parseInt(request.headers.get('content-length') || '0')
}
});
```
**Reason:** R2 requires known length for streams. Unknown length may cause silent truncation.
## S3 SDK Region Configuration
```typescript
// ❌ WRONG: Missing region breaks ALL S3 SDK calls
const s3 = new S3Client({
endpoint: `https://${accountId}.r2.cloudflarestorage.com`,
credentials: { ... }
});
// ✅ CORRECT: MUST set region='auto'
const s3 = new S3Client({
region: 'auto', // REQUIRED
endpoint: `https://${accountId}.r2.cloudflarestorage.com`,
credentials: { ... }
});
```
**Reason:** S3 SDK requires region. R2 uses 'auto' as placeholder.
## Local Development Limits
```typescript
// ❌ Miniflare/wrangler dev: Limited R2 support
// - No multipart uploads
// - No presigned URLs (requires S3 SDK + network)
// - Memory-backed storage (lost on restart)
// ✅ Use remote bindings for full features
wrangler dev --remote
// OR: Conditional logic
if (env.ENVIRONMENT === 'development') {
// Fallback for local dev
} else {
// Full R2 features
}
```
## Presigned URL Expiry
```typescript
// ❌ WRONG: URL expires but no client validation
const url = await getSignedUrl(s3, command, { expiresIn: 60 });
// 61 seconds later: 403 Forbidden
// ✅ CORRECT: Return expiry to client
return Response.json({
uploadUrl: url,
expiresAt: new Date(Date.now() + 60000).toISOString()
});
```
## Limits
| Limit | Value |
|-------|-------|
| Object size | 5 TB |
| Multipart part count | 10,000 |
| Multipart part min size | 5 MB (except last) |
| Batch delete | 1,000 keys |
| List limit | 1,000 per request |
| Key size | 1024 bytes |
| Custom metadata | 2 KB per object |
| Presigned URL max expiry | 7 days |
## Common Errors
### "Stream upload failed" / Silent Truncation
**Cause:** Stream length unknown or Content-Length missing
**Solution:** Buffer data or pass explicit Content-Length
### "Invalid credentials" / S3 SDK
**Cause:** Missing `region: 'auto'` in S3Client config
**Solution:** Always set `region: 'auto'` for R2
### "Object not found"
**Cause:** Object key doesn't exist or was deleted
**Solution:** Verify object key correct, check if object was deleted, ensure bucket correct
### "List compatibility error"
**Cause:** Missing or old compatibility_date, or flag not enabled
**Solution:** Set `compatibility_date >= 2022-08-04` or enable `r2_list_honor_include` flag
### "Multipart upload failed"
**Cause:** Part sizes not uniform or incorrect part number
**Solution:** Ensure uniform size except final part, verify part numbers start at 1
Related skills
| Skill | Stars | Updated | Works with | Status | Install |
|---|---|---|---|---|---|
| writing-skillsobra/superpowersUse when creating new skills, editing existing skills, or verifying skills work before deployment | Stars: 322k | Updated | Claude CodeCodex | Verified | Install |
| xlsxanthropics/skillsUse this skill any time a spreadsheet file is the primary input or output. This means any task where the user wants to: open, read, edit, or fix an existing .xlsx, .xlsm, .xltx, .csv, or .tsv file (e.g., adding columns, computing formulas, formatting, charting, cleaning messy data); create a new spreadsheet from scratch or from other data sources; or convert between tabular file formats. Trigger especially when the user references a spreadsheet file by name or path — even casually (like "the xlsx in my downloads") — and wants something done to it or produced from it. Also trigger for cleaning or restructuring messy tabular data files (malformed rows, misplaced headers, junk data) into proper spreadsheets. The deliverable must be a spreadsheet file. Do NOT trigger when the primary deliverable is a Word document, HTML report, standalone Python script, database pipeline, or Google Sheets API integration, even if tabular data is involved. | Stars: 197k | Updated | Claude CodeCodex | Verified | Install |
| shipping-and-launchaddyosmani/agent-skillsPrepares production launches. Use when preparing to deploy to production, or when asking what needs to be in place before shipping. Use when you need a pre-launch checklist, when setting up monitoring, when planning a staged rollout, or when you need a rollback strategy. | Stars: 119k | Updated | Claude CodeCodex | Verified | Install |
| childhoodthedotmack/claude-memBabysit a shipped release after merge, publication, or deployment. Verify published packages, production behavior, installed plugins, and late CI or user reports until the observation window is clean; use babysit for PR readiness before release. | Stars: 118k | Updated | Claude CodeCodex | Verified | Install |