file-uploads

Implements secure file uploads with S3, R2, presigned URLs, and multipart handling.

Updated Aug 11, 2026
One-click install
npx skills add https://github.com/DucCuong159/Realtime-chatapp --skill file-uploads-duccuong159
Or copy as Structured Prompt for Agent▼
Please help me install this Agent Skill.
Skill: file-uploads
Source: https://github.com/DucCuong159/Realtime-chatapp/tree/main/.agent/skills/file-uploads
Command: npx skills add https://github.com/DucCuong159/Realtime-chatapp --skill file-uploads-duccuong159

SYSTEM DOCUMENTATION & REQUIREMENTS

💡 This Skill requires file-type, formidable, multer.

What problem does it solve? Handling file uploads safely is error-prone: trusting client-provided file types lets malware through, missing size limits cause denial of service, and unsanitized filenames enable path traversal attacks. This Skill provides battle-tested guidance for building secure, performant upload pipelines. ## Core Features & Use Cases - Security-First Validation: Verify actual file types via magic bytes instead of trusting extensions or Content-Type headers, and sanitize filenames to prevent path traversal. - Cloud Storage Patterns: Covers S3 and Cloudflare R2 workflows including presigned URLs with short expiry, cache-control headers, and multipart uploads for large files. - Resource Protection: Enforce upload size limits with Multer or Formidable, stream large files instead of buffering, and avoid memory exhaustion. - Use Case: When building a profile photo upload feature, use this Skill to validate images with the file-type library, generate safe UUID-based filenames, and issue short-lived presigned URLs so clients upload directly to R2 without proxying through your server. ## Quick Start Ask the AI to implement a secure image upload endpoint using presigned URLs with magic-byte validation and a 10MB size limit.

Frequently Asked Questions about file-uploads

High-intent search queries and answers about installing and using this skill.

FAQPage Schema
How do I validate uploaded file types in Node.js?▼

Validate uploaded files by checking magic bytes with the file-type library instead of trusting extensions or Content-Type headers. Use fileTypeFromBuffer for buffers or fileTypeFromStream for streams, then compare the detected MIME type against an allowlist like image/jpeg, image/png, or image/webp.

How to prevent path traversal in file upload filenames?▼

Prevent path traversal by never using user-supplied filenames directly in file paths. Extract the base name with path.basename, strip unsafe characters, or better yet generate a new name with crypto.randomUUID plus a validated extension from an allowlist.

Should I use presigned URLs or proxy uploads through my server?▼

Presigned URLs are preferred because clients upload directly to S3 or R2 without consuming server bandwidth or memory. Set short expiry times around 5 minutes and return them with Cache-Control: no-store headers so they cannot be cached and reused.

What file size limits should I set for uploads?▼

Set explicit size limits such as 10MB using Multer's limits.fileSize or Formidable's maxFileSize option, and add a client-side pre-check for early feedback. Without limits, attackers can exhaust disk and memory or inflate storage bills with oversized files.

Why is checking only the file extension dangerous for uploads?▼

Checking only extensions is dangerous because attackers can rename malware.exe to image.jpg and bypass filters. Extensions and Content-Type headers are client-controlled and easily faked, so the actual file content must be inspected via magic bytes.