file-uploads-and-storage
Skill2 starsChanged 6 months agoMITView on GitHub
Use when handling user file uploads — upload directly to S3/R2/Supabase Storage with presigned URLs, validate type and size, scope objects per tenant, and serve them back securely without proxying bytes through your server.
1 other project uses a version of this.
Adopted by
Most recently taken up by
- alyanhaider/system-architecturetheir own version, first seen Jun 19, 2026
Other versions1 project uses a version of this.
Word for word · 0
None found.
Edited · 0
None found.
Wrote their own version · 1
- alyanhaider/system-architecture★ 2same 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 repository14 other files it gives its agents.
- api-routes-and-validationSkill
- authenticationSkill
- authorization-rbacSkill
- background-jobsSkill
- data-access-layerSkill
- database-schemaSkill
- deployment-and-ciSkill
- environment-and-configSkill
- multi-tenancySkill
- observability-and-errorsSkill
- payments-stripeSkill
- project-scaffoldingSkill
- subscription-billingSkill
- transactional-emailSkill
The file
Files
File Uploads & Storage
Overview
Don't stream uploads through your app server — it's slow, memory-hungry, and hits serverless body limits. Instead, issue a presigned URL so the browser uploads directly to object storage (S3, Cloudflare R2, or Supabase Storage), then store only the object key + metadata in your DB. Validate type/size before signing, namespace keys per tenant, and serve private files via short-lived signed download URLs.
When to use
- Users upload avatars, attachments, imports, or documents.
- Files are large or uploads are slow/timing out through your API.
- You need per-tenant access control on stored files.
Presigned upload
// src/app/api/uploads/sign/route.ts
import { z } from "zod";
import { PutObjectCommand, S3Client } from "@aws-sdk/client-s3";
import { getSignedUrl } from "@aws-sdk/s3-request-presigner";
import { requireOrg } from "@/server/auth/active-org";
const Body = z.object({
filename: z.string().max(200),
contentType: z.enum(["image/png", "image/jpeg", "application/pdf"]), // allowlist
size: z.number().int().positive().max(10 * 1024 * 1024), // 10MB cap
});
const s3 = new S3Client({ region: "auto" });
export async function POST(req: Request) {
const { org } = await requireOrg(new URL(req.url).searchParams.get("org")!);
const { filename, contentType } = Body.parse(await req.json());
const key = `orgs/${org.id}/${crypto.randomUUID()}/${filename}`; // tenant-scoped key
const url = await getSignedUrl(
s3,
new PutObjectCommand({ Bucket: "uploads", Key: key, ContentType: contentType }),
{ expiresIn: 60 },
);
return Response.json({ url, key });
}The client PUTs the file to url, then tells your API the key to persist (in a tenant-scoped row).
Serving files back
- Private by default. Buckets block public reads; generate short-lived signed GET URLs on demand.
- Authorize downloads — verify the requester's org owns the
keybefore signing. - Process async — thumbnails/virus-scan/transcode run in
background-jobs, keyed off the upload.
Pitfalls
- Proxying bytes through the API — memory blowups and serverless payload limits; use presigned URLs.
- Trusting client-reported content-type/size — allowlist types and cap size in the signing request; verify after upload.
- Public buckets for private data — leaks every file via a guessable URL. Keep private, sign reads.
- Un-namespaced keys — without
orgs/<id>/..., one tenant can reference another's objects. - Storing the file in Postgres — store the key + metadata; keep bytes in object storage.
Hand-off
Direct-to-storage uploads with tenant-scoped keys. background-jobs post-processes; data-access-layer stores keys; observability-and-errors tracks failures.
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.

