Skip to content
file-upload-handling logo

File Upload Handling

file-upload-handling

Implement secure file upload handling with validation, virus scanning, storage management, and serving files efficiently. Use when building file upload features, managing file storage, and implementing file download systems.

aj-geddes/useful-ai-prompts365installs351stars

SKILL.md

Full skill instructions

File Upload Handling

Table of Contents

Overview

Build secure and robust file upload systems with validation, sanitization, virus scanning, efficient storage management, CDN integration, and proper file serving mechanisms across different backend frameworks.

When to Use

  • Implementing file upload features
  • Managing user-uploaded documents
  • Storing and serving media files
  • Implementing profile picture uploads
  • Building document management systems
  • Handling bulk file imports

Quick Start

Minimal working example:

# config.py
import os

class Config:
    MAX_CONTENT_LENGTH = 50 * 1024 * 1024  # 50 MB
    UPLOAD_FOLDER = 'uploads'
    ALLOWED_EXTENSIONS = {'txt', 'pdf', 'png', 'jpg', 'jpeg', 'gif', 'docx', 'doc'}
    UPLOAD_DIRECTORY = os.path.join(os.path.dirname(__file__), UPLOAD_FOLDER)

# file_service.py
import os
import mimetypes
import hashlib
import secrets
from werkzeug.utils import secure_filename
from datetime import datetime
import magic
import aiofiles

class FileUploadService:
    def __init__(self, upload_dir, allowed_extensions, max_size=50*1024*1024):
        self.upload_dir = upload_dir
        self.allowed_extensions = allowed_extensions
        self.max_size = max_size
        self.mime = magic.Magic(mime=True)
// ... (see reference guides for full implementation)

Reference Guides

Detailed implementations in the references/ directory:

GuideContents
Python/​Flask File UploadPython/​Flask File Upload
Node.js Express File Upload with MulterNode.js Express File Upload with Multer
FastAPI File UploadFastAPI File Upload
S3/​Cloud Storage IntegrationS3/​Cloud Storage Integration

Best Practices

✅ DO

  • Validate file extensions and MIME types
  • Check file size before processing
  • Use secure filenames to prevent directory traversal
  • Store files outside web root
  • Implement virus scanning
  • Use CDN for file delivery
  • Generate signed URLs for direct access
  • Log file upload/​download events
  • Implement access control checks
  • Clean up temporary files

❌ DON'T

  • Trust user-provided filenames
  • Store files in web-accessible directories
  • Allow arbitrary file types
  • Skip virus scanning for uploaded files
  • Expose absolute file paths
  • Allow unlimited file sizes
  • Ignore access control
  • Use predictable file paths
  • Store sensitive metadata in filenames
  • Forget to validate file content

More skills from aj-geddes

jenkins-pipeline logo
aj-geddes/useful-ai-prompts

jenkins-pipeline

Build Jenkins declarative and scripted pipelines with stages, agents, parameters, and plugins. Implement multi-branch pipelines and deployment automation.

351 1.8K
View
ansible-automation logo
aj-geddes/useful-ai-prompts

ansible-automation

Infrastructure automation and configuration management using Ansible playbooks, roles, and inventory. Use for deploying applications, patching, and managing servers.

351 1.7K
View
ios-swift-development logo
aj-geddes/useful-ai-prompts

ios-swift-development

Develop native iOS apps with Swift. Covers MVVM architecture, SwiftUI, URLSession for networking, Combine for reactive programming, and Core Data persistence.

351 1.5K
View
android-kotlin-development logo
aj-geddes/useful-ai-prompts

android-kotlin-development

Develop native Android apps with Kotlin. Covers MVVM with Jetpack, Compose for modern UI, Retrofit for API calls, Room for local storage, and navigation architecture.

351 1.5K
View
wireframe-prototyping logo
aj-geddes/useful-ai-prompts

wireframe-prototyping

Create wireframes and interactive prototypes to visualize user interfaces and gather feedback early. Use tools and techniques to communicate design ideas before development.

351 1.4K
View
flask-api-development logo
aj-geddes/useful-ai-prompts

flask-api-development

Develop lightweight Flask APIs with routing, blueprints, database integration, authentication, and request/response handling. Use when building RESTful APIs, microservices, or lightweight web services with Flask.

351 1.4K
View
nginx-configuration logo
aj-geddes/useful-ai-prompts

nginx-configuration

Configure Nginx web server for high-performance reverse proxy, load balancing, SSL/TLS, caching, and API gateway functionality.

351 1.4K
View
markdown-documentation logo
aj-geddes/useful-ai-prompts

markdown-documentation

Master markdown formatting, GitHub Flavored Markdown, README files, and documentation formatting. Use when writing markdown docs, READMEs, or formatting documentation.

351 1.3K
View
css-architecture logo
aj-geddes/useful-ai-prompts

css-architecture

Organize CSS using BEM, SMACSS, and CSS-in-JS patterns. Use when building scalable, maintainable styling systems with proper naming conventions.

351 712
View
penetration-testing logo
aj-geddes/useful-ai-prompts

penetration-testing

Ethical hacking and security testing methodologies using penetration testing tools, exploit frameworks, and manual security validation. Use when assessing application security posture and identifying exploitable vulnerabilities.

351 712
View
event-sourcing logo
aj-geddes/useful-ai-prompts

event-sourcing

Implement event sourcing and CQRS patterns using event stores, aggregates, and projections. Use when building audit trails, temporal queries, or systems requiring full history.

351 711
View
responsive-web-design logo
aj-geddes/useful-ai-prompts

responsive-web-design

Create responsive layouts using CSS Grid, Flexbox, media queries, and mobile-first design. Use when building adaptive interfaces that work across all devices.

351 699
View

Popular AI tools

Kaiber logo
Video

Kaiber

Generate, edit, and beat-sync AI video with leading models in one workspace.

Paid
View
Vimcal logo
Productivity

Vimcal

The world's fastest calendar for remote work

Free
View

Transform Your Design with AI Designer by ImgCreator.ai

Freemium
View
Akool AI logo
Content & writing

Akool AI

Revolutionizing Video Production with AI-Powered Creativity

Paid
View

Extend an image past the frame and let AI fill the new aspect ratio.

Freemium
View
StarByFace logo
Security

StarByFace

Discover your celebrity doppelgänger with StarByFace!

Free
View
C

ChainClarity explains 700+ crypto whitepapers in plain English, with layered summaries, comparisons, research tools, alerts, and a $4.99 Pro plan.

Freemium
View
Opus Clip logo
Coding & apps

Opus Clip

Opus.ai: Revolutionize Your Web Experience

Free
View