{"success":true,"name":"design-file-upload-apis-around-limits-types-and-storage-not-","description":"Adding an endpoint that accepts file uploads","category":"ai-brimind","path":"ai-brimind/design-file-upload-apis-around-limits-types-and-storage-not-/SKILL.md","file":"SKILL.md","content":"---\nname: design-file-upload-apis-around-limits-types-and-storage-not-\ndescription: \"Adding an endpoint that accepts file uploads\"\n---\n\n# Design File Upload APIs Around Limits, Types, and Storage — Not req.body\n\n## When to use\nYou are building an upload endpoint, and size limits, type validation, and where bytes actually flow have not been explicitly designed.\n\n## Example request\nNo size limit on uploads → one 2GB file fills memory or disk and takes the server down; a hard limit is the first line. — File type checked by extension only → 'photo.jpg' is an executable; checking real content type (magic bytes) is the honest validation. — Files buffered fully in the app then written → memory spikes per upload; streaming to storage is the mechanism. — Files saved on the server's local disk → second instance can't see them and deploys wipe them; object storage (or the platform's upload flow, like presigned URLs) is the standard home.\n\n## Instructions\nAct as an upload gatekeeper who treats every incoming file as oversized, mislabeled, and hostile until checked. For the upload endpoint: 1) Set explicit limits first — max file size, allowed types, max files per request — enforced server-side at the web-server/framework layer, rejected with clear 4xx errors. 2) Validate the actual content, not the filename: check real MIME/magic bytes against the whitelist; never trust extensions or client-sent content-type headers. 3) Decide where bytes flow before coding: check the platform's standard mechanism (object storage, presigned/direct upload URLs, the framework's streaming multipart handling) — streaming through or around your app beats buffering whole files in memory. 4) Store with generated names in a location that is never executable or path-controlled by the client — user-controlled paths are traversal attacks waiting. 5) Plan the lifecycle: where metadata lives, how orphaned files get cleaned, how downloads are authorized. Only ship once an oversized file, a fake-extension file, and a legit file have all been tested through the flow, and explain how each guard blocks its specific abuse rather than assuming friendly uploaders.\n\n## Metadata\n- role: developer\n- level: tactical\n- places: vibeCoding\n- origin: ai.brimind.pro skill #911\n","linked_files":[],"origin":"ai.brimind.pro","owner_id":null,"source":"router"}