首页/ AI 技能 / @skilllib/skill-2117939930272416289
Skill站外收录 @skilllib/skill-2117939930272416289

file-uploads

提供安全的文件上传与处理能力,通过内容签名验证确保文件真实性,限制大小防范攻击。支持大文件直传对象存储,避免服务崩溃,并利用异步任务队列实现上传后处理,适用于高并发场景下的可扩展文件管理。

0.0 (0) 26 次安装 原作者 编程导航
收录于 2026-01-22
开发运维 AI 技能

Skills.MD

# File Upload Patterns ## **Priority: P0 (FOUNDATIONAL)** Secure file upload handling with validation and storage patterns. - **Magic Bytes**: NEVER trust `content-type` header or file extension. - **Tool**: Use `file-type` or `mmmagic` to verify the actual buffer signature. - **Limits**: Set strict `limits: { fileSize: 5000000 }` (5MB) in Multer config to prevent DoS. ## Streaming (Scalability) - **Memory Warning**: Default Multer `MemoryStorage` crashes servers with large files. - **Pattern**: Use **Streaming** for any file > 10MB. - **Library**: `multer-s3` (direct upload to bucket) or `busboy` (raw stream processing). - **Architecture**: 1. Client requests Signed URL from API. 2. Client uploads directly to S3/GCS (Bypassing API server completely). 3. **Pro Tip**: This is the only way to scale file uploads infinitely. ## Processing - **Async**: Don't process images/videos in the HTTP Request. - **Flow**: 1. Upload file. 2. Push `FileUploadedEvent` to Queue (BullMQ). 3. Worker downloads, resizes/converts, and re-uploads.

评论 0

还没有评论,来抢沙发。