---
name: role-fullstack-file-upload-handling-2b332a946b90
description: Implement file upload flows with presigned URLs (S3, GCS, R2), multipart/tus resumable uploads, Sharp image processing, drag-and-drop UI with progress indicators, server-side MIME validation via magic bytes, virus scanning, and CDN serving. Use when adding profile pictures, document attachments, media galleries, or any user-submitted file feature.
allowed-tools: Read, Grep, Glob, Bash
---

# File Upload Handling

## When to use
- Implementing profile picture or avatar upload
- Building document attachment or media gallery features
- Handling bulk file imports or exports
- Adding drag-and-drop upload UX with progress feedback
- Setting up CDN serving for uploaded assets
- Adding virus scanning or strict file type enforcement

## Core principles
1. **Never trust client-reported types** — always validate MIME type server-side by reading magic bytes, not the `Content-Type` header
2. **Presigned URLs over server proxy** — upload directly from client to S3/GCS; never stream file bytes through the application server
3. **Rename to UUIDs** — strip original filenames entirely to prevent path traversal, collisions, and enumeration attacks
4. **Process media asynchronously** — run Sharp resizing and format conversion in BullMQ jobs, not in the request handler
5. **Clean up orphans** — run a periodic job to delete uploads unreferenced in the database; storage costs compound silently

## Reference Files

- `references/upload-strategies.md` — strategy selection table (multipart form vs presigned URL vs tus), presigned URL flow steps, AWS SDK v3 code example, progress indicator with XMLHttpRequest, CDN serving with signed URLs and cache headers
- `references/validation-security.md` — client-side vs server-side validation responsibilities, magic byte MIME checking, ClamAV/cloud malware scanning, Sharp image processing pipeline, react-dropzone UI patterns, common pitfalls


---
Source attribution: rnavarych
Original project: https://github.com/rnavarych/alpha-engineer/blob/c5b74102c7fd584af3d344ba7c331a7bbec3c729/plugins/roles/role-fullstack/skills/file-upload-handling/SKILL.md
License: MIT
License information: https://opensource.org/license/mit
Original upstream instructions; downloaded from Mega AI Hub.

## Upstream license notice

MIT License

Copyright (c) 2026 Raman Navarych

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.



# Mega AI Hub resource metadata

Creator / publisher: rnavarych
Original project: https://github.com/rnavarych/alpha-engineer/blob/c5b74102c7fd584af3d344ba7c331a7bbec3c729/plugins/roles/role-fullstack/skills/file-upload-handling/SKILL.md
Attribution basis: Source repository record

Fields of work: Development & Engineering
Roles: Backend Developer, Frontend Developer, Full-Stack Developer
Specialties: Backend, Frontend
Tools: AWS, GCP, Sharp
Country applicability: Country not specified
Classification basis: Source catalog labels
Instruction SHA-256: b0ed80b07ac690c92e039cbe2c1660141e0d2d8469e682725ee577c888290184
