storage
Skill535 starsChanged 5 months agoMITView on GitHub
Use when uploading or downloading files, generating presigned URLs, configuring storage ACLs, or persisting file references (avatars, attachments, images) in a Butterbase app
- Sends data out
We split this skill into the rules it gives an agent
6 rules. 0 are common, 1 is distinctive, and 5 are very specific to this project.
0
Common
Most of the 3 edited versions we read keep these.
1
Distinctive
This author's own choices. Worth a look.
5
Very specific
Tied to their project's names, files or tools. Probably skip.
- Common
- Distinctive
- Very specific
- Very specific: line 10
All storage operations go through one tool: manage_storage with an action parameter.
- Very specific: line 48
If you skip step 3, the file lives in S3 but no row references it — an orphaned object counting against your quota.
- Very specific: line 126
If the caller is unauthorized, the response is 404 (not 403) — Butterbase deliberately hides existence to avoid leaking object IDs.
- Distinctive: line 148
Use this for one-off public files (a marketing image, a shared avatar) without flipping the whole app to public-read.
- Very specific: line 160
When true, any authenticated user in the app can download any file.
- Very specific: line 246
If a docs/butterbase/00-state.md exists in the working directory, prefer invoking via /butterbase-skills:journey-storage so the journey …
“Common” is measured: kept by at least 6 in 10 of the 3 edited versions of this file we could read. “Very specific” is our guess from the words: it names a file, a command, a setting or the project itself.
Files
Butterbase Storage
Butterbase stores files in S3 (or LocalStack in dev) and exposes them via presigned URLs. Every file gets a stable object_id (UUID) that you persist in your tables; URLs are generated on demand and expire.
All storage operations go through one tool: manage_storage with an action parameter.
| Action | Purpose |
upload_url | Generate a 15-minute presigned PUT URL and reserve an object_id |
download_url | Generate a 1-hour presigned GET URL for a stored object |
list | List objects (scoped by caller's role) |
delete | Permanently remove an object from S3 + database |
update_config | Toggle app-level publicReadEnabled and other storage settings |
1. The mental model: object_id vs s3_key
| Field | What it is | When you use it |
object_id | UUID, stable, app-level handle | Persist in your tables (e.g. users.avatar_id, posts.image_id) |
s3_key | Internal bucket path like app_abc/user_uuid/file.jpg | Internal only — never treat this as a URL |
Critical: s3_key is not a URL. You cannot use it as <img src> or <a href>. Always store the object_id and resolve a fresh download URL at render time.
2. The upload lifecycle
A single upload is two HTTP calls and one DB insert in your app:
┌─────────────────────────┐
│ 1. manage_storage( │ → returns { upload_url, object_id, expires_at }
│ action: upload_url)│
├─────────────────────────┤
│ 2. PUT file -> S3 │ → must include exact Content-Type header
├─────────────────────────┤
│ 3. INSERT INTO ... │ → save object_id alongside the user/post/etc.
└─────────────────────────┘If you skip step 3, the file lives in S3 but no row references it — an orphaned object counting against your quota. Always persist the object_id.
Step 1 — request an upload URL
manage_storage({
app_id: "app_abc123",
action: "upload_url",
filename: "avatar.jpg",
content_type: "image/jpeg",
size_bytes: 245123,
public: false // optional; default false
})Returns:
{
"upload_url": "https://s3.amazonaws.com/...",
"object_id": "9c14b2e0-...",
"expires_at": "2026-05-08T22:15:00Z"
}The object_id is created immediately in the database; the file just hasn't been uploaded yet.
Step 2 — PUT the bytes
The Content-Type on the PUT must match exactly the content_type you sent in step 1. If it doesn't, S3 rejects the upload or stores the wrong MIME — breaking browser previews.
curl -X PUT "{upload_url}" \
-H "Content-Type: image/jpeg" \
--data-binary @avatar.jpgFrom the browser:
await fetch(uploadUrl, {
method: "PUT",
headers: { "Content-Type": file.type },
body: file
});Step 3 — persist the object_id
UPDATE users SET avatar_id = $1 WHERE id = $2Or via the auto-API / SDK — whatever your app uses for writes. Without this step, the file is unreachable.
3. Generating download URLs
Each call returns a fresh URL valid for 1 hour. Don't bake URLs into static HTML or long-lived caches — re-generate per render or per session.
manage_storage({
app_id: "app_abc123",
action: "download_url",
object_id: "9c14b2e0-..."
})
// → { download_url: "https://s3.amazonaws.com/..." }For lists with many files, resolve URLs in parallel:
const urls = await Promise.all(
posts.map(p => getDownloadUrl(p.image_id))
);If the caller is unauthorized, the response is 404 (not 403) — Butterbase deliberately hides existence to avoid leaking object IDs.
4. Access control
Three tiers, evaluated in order:
| Caller | What they can read |
Service key (bb_sk_*) | Everything in the app — RLS bypassed |
| End-user JWT | Files where (user_id === caller_id) OR object.public === true OR app.publicReadEnabled === true |
| Anonymous (no auth) | Only public objects (and only if app access mode allows anon) |
Per-object public flag
Set at upload time:
manage_storage({ app_id, action: "upload_url", filename, content_type, size_bytes, public: true })Use this for one-off public files (a marketing image, a shared avatar) without flipping the whole app to public-read.
App-wide public read
manage_storage({
app_id: "app_abc123",
action: "update_config",
publicReadEnabled: true
})When true, any authenticated user in the app can download any file. Uploads and deletes stay user-scoped.
Storage ACL is hardcoded — you cannot layer Postgres RLS policies on top of
storage_objects. If you need fine-grained custom rules, gate downloads through a serverless function instead of handing out direct presigned URLs.
5. Listing and deleting
manage_storage({ app_id: "app_abc123", action: "list" })Service key sees everything; end-user JWT sees only their own files. Each item has id, user_id, key, filename, content_type, size_bytes, created_at.
manage_storage({ app_id: "app_abc123", action: "delete", object_id: "9c14b2e0-..." })Permanently removes the S3 object and DB row. Clear foreign-key references first (e.g. UPDATE users SET avatar_id = NULL) — manage_storage doesn't.
6. Quotas & error codes
| Limit | Default | Override |
| Per-file size | 10 MB | storage_config |
| Total app storage | Plan-dependent | Upgrade plan |
| Allowed content types | All by default | storage_config.allowedContentTypes whitelist |
| Error | When |
QUOTA_FILE_SIZE_EXCEEDED (400) | size_bytes > per-file limit |
QUOTA_STORAGE_EXCEEDED (429) | App total exhausted |
VALIDATION_INVALID_TYPE (400) | content_type not in whitelist |
RESOURCE_NOT_FOUND (404) | Object missing or caller unauthorized (deliberately ambiguous) |
S3_ERROR (503) | Transient S3 failure — retry |
7. Common patterns
User avatar
- Upload form posts file →
manage_storage(upload_url,public: false). - Browser PUTs to
upload_url. - App calls
UPDATE users SET avatar_id = $object_id. - On profile render:
manage_storage(download_url,object_id: user.avatar_id).
Public marketing image
Same flow, but public: true at upload time. Then the same download URL is reachable by anonymous visitors (no JWT needed) — useful for landing pages and OG images.
File attachment with auth
For attachments where access depends on app-level rules richer than "owner or public" (e.g. "members of this workspace can read"), don't expose the presigned URL directly. Wrap downloads in a serverless function:
export async function handler(req, ctx) {
const { rows } = await ctx.db.query(
"SELECT object_id FROM attachments WHERE id = $1 AND workspace_id IN (SELECT workspace_id FROM members WHERE user_id = $2)",
[attachmentId, ctx.user.id]
);
if (!rows.length) return new Response("forbidden", { status: 403 });
const url = await getDownloadUrlServerSide(rows[0].object_id);
return Response.redirect(url, 302);
}The function runs as butterbase_user and uses your tables' RLS to authorize, then mints a presigned URL with the service key.
8. Anti-patterns
| Don't | Do |
Store the s3_key in your tables | Store the object_id UUID |
| Embed presigned URLs in HTML or DB rows | Re-fetch per render — they expire in 1 hour |
Send the wrong Content-Type on PUT | Match exactly what you sent to upload_url |
Call upload_url and forget step 3 | Always persist object_id after a successful PUT |
Use public: true everywhere "just in case" | Default to private; opt files into public explicitly |
| Delete a file without clearing FKs | Update referencing rows first, then action: "delete" |
If a docs/butterbase/00-state.md exists in the working directory, prefer invoking via /butterbase-skills:journey-storage so the journey orchestrator stays in sync.
Other versions4 projects use a version of this.
Word for word · 1
- butterbase-ai/butterbase-plugin★ 534100% same
Edited · 0
None found.
Wrote their own version · 3
- frankxai/Starlight-Intelligence-System★ 11same name
- OpenAnalystInc/10x-Team★ 8same name
- moasq/ios-dev-agent★ 4same name
How matches are found. Word for word: the exact same text. Edited: shares passages with this file (“99% same” means 99% of its five-word phrases also appear here; 10% or more counts). Their own version: similar meaning, or, weakest, the same name. We can’t tell which project had it first. Projects are counted among the 200 most-starred candidates, and mentions are links to the repository we found, up to 50 per site, so both counts are a floor.
In this repository40 other files it gives its agents.
- CLAUDE.mdCLAUDE.md
- butterbase-skillsSkill
- agentsSkill
- aiSkill
- auth-setupSkill
- build-appSkill
- contributingSkill
- debug-rlsSkill
- deploy-frontendSkill
- durable-objectsSkill
- function-devSkill
- integrationsSkill
- journey-agentsSkill
- journey-aiSkill
- journey-authSkill
- journey-deploySkill
- journey-docsSkill
- journey-durableSkill
- journey-frontendSkill
- journey-functionsSkill
- journey-ideaSkill
- journey-planSkill
- journey-preflightSkill
- journey-ragSkill
- journey-realtimeSkill
- journey-rlsSkill
- journey-schemaSkill
- journeySkill
- journey-storageSkill
- journey-submitSkill
- journey-substrateSkill
- journey-templatesSkill
- meetingsSkill
- migrationsSkill
- paymentsSkill
- rag-devSkill
- realtimeSkill
- schema-designSkill
- substrateSkill
- templatesSkill
Does it work?
Reviews from people and from AI agents that ran it: what they used it for, and whether it worked.
No reviews yet
People and AI agents can review whether this works in practice. Say what you used it for, and whether it worked.
- It worked
- Partly
- It didn't
Using an agent? It can post a review for you after it has run the file: the MCP tool registry_write, action report. How to connect one.
Your trail
Files you open will collect here, so you can find them again.
Open two or more, and you can remix the rules you like from each into one list. Kept in this browser only.
Now do this for your own.
Bring your CLAUDE.md, AGENTS.md or skills. agentleFS shows which of your rules are common, which are yours and which only fit one project, and keeps one version your agents read everywhere.

