Contents

Chapter 1

Features

This chapter covers the core features and capabilities of File Upload Handler.

Features

  • Magic byte verification: detect real file types (PNG, JPEG, GIF, PDF, ZIP, GZIP) regardless of extension
  • Filename sanitization: strip path traversal attacks, null bytes, and special characters
  • Blocked extensions: reject dangerous file types (.exe, .bat, .sh, .php, etc.)
  • SHA-256 file hashing: generate content-based hashes for deduplication and integrity checks
  • Virus scanner hooks: plug in ClamAV or any command-line scanner
  • Date-organized storage: auto-create YYYY/MM/DD subdirectories
  • File renaming: optional UUID-based renaming to prevent filename collisions
  • Configurable size limits: reject files over a maximum size threshold
  • Python 3.10+ stdlib only — no pip installs required

Quick Start

bash
# Upload a file with default settings
python src/file_upload_handler.py --file photo.jpg

# Upload to a custom directory with 5MB limit
python src/file_upload_handler.py --file report.pdf --upload-dir ./uploads --max-size 5

# Upload without renaming (keep original filename)
python src/file_upload_handler.py --file data.csv --no-rename

# Upload without date subdirectories
python src/file_upload_handler.py --file image.png --no-date-dirs

# Upload with virus scanning
python src/file_upload_handler.py --file document.pdf --scanner "clamscan"

# Run the built-in demo
python src/file_upload_handler.py --demo
Chapter 2

CLI Reference

Follow this guide to get File Upload Handler up and running in your environment.

CLI Reference

FlagDescription
--file FILEPath to the file to upload/process
--upload-dir DIRDestination directory (default: uploads/)
--max-size MBMaximum file size in megabytes (default: 10)
--no-renameKeep original filename instead of generating UUID
--no-date-dirsDon't create date-based subdirectories
--scanner CMDExternal virus scanner command (e.g., clamscan)
--demoRun a built-in demo showing all features

Programmatic Usage

python
from file_upload_handler import FileUploadHandler, UploadConfig

# Configure the handler
config = UploadConfig(
    upload_dir="./uploads",
    max_size_mb=10,
    allowed_types=["image/png", "image/jpeg", "application/pdf"],
    blocked_extensions=[".exe", ".bat", ".sh", ".php"],
    rename_files=True,
    preserve_extension=True,
    date_subdirs=True,
    verify_magic_bytes=True,
)

handler = FileUploadHandler(config)

# Process an upload
result = handler.process_upload("/path/to/file.jpg")
if result.success:
    print(f"Saved to: {result.destination}")
    print(f"SHA-256:  {result.sha256}")
    print(f"Size:     {result.size_bytes} bytes")
    print(f"MIME:     {result.mime_type}")
else:
    print(f"Rejected: {result.error}")
Chapter 3
🔒 Available in full product

Security Features

Chapter 4
🔒 Available in full product

File Structure

You’ve reached the end of the free preview

Get the full File Upload Handler and unlock everything.

All Chapters

Get the complete guide with every chapter unlocked, including code samples, diagrams, and best practices.

Full Tool Suite

Access all interactive tools with complete data, all workload profiles, and the full scenario library.

Source Files

Downloadable source code, configuration files, and working examples from every chapter.

Lifetime Updates

Free updates for life. Every new chapter, tool, and improvement included.

Buy Now — $19 →
📦 Free sample included — download another copy for the full product.
File Upload Handler v1.0.0 — Free Preview