This chapter covers the core features and capabilities of File Upload Handler.
YYYY/MM/DD subdirectories# 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 --demoFollow this guide to get File Upload Handler up and running in your environment.
| Flag | Description |
|---|---|
--file FILE | Path to the file to upload/process |
--upload-dir DIR | Destination directory (default: uploads/) |
--max-size MB | Maximum file size in megabytes (default: 10) |
--no-rename | Keep original filename instead of generating UUID |
--no-date-dirs | Don't create date-based subdirectories |
--scanner CMD | External virus scanner command (e.g., clamscan) |
--demo | Run a built-in demo showing all features |
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}")Get the full File Upload Handler and unlock everything.
Get the complete guide with every chapter unlocked, including code samples, diagrams, and best practices.
Access all interactive tools with complete data, all workload profiles, and the full scenario library.
Downloadable source code, configuration files, and working examples from every chapter.
Free updates for life. Every new chapter, tool, and improvement included.