File Upload Handling

File Upload Handling

Helps an AI agent build secure file upload features with validation, virus scanning, storage management and efficient serving across Flask, FastAPI and Express.

Skill files7 files

references/

scripts/

templates/

SKILL.md103 lines
1
---
2
name: file-upload-handling
3
description: >
4
Implement secure file upload handling with validation, virus scanning, storage
5
management, and serving files efficiently. Use when building file upload
6
features, managing file storage, and implementing file download systems.
7
---
8
9
# File Upload Handling
10
11
## Table of Contents
12
13
- [Overview](#overview)
14
- [When to Use](#when-to-use)
15
- [Quick Start](#quick-start)
16
- [Reference Guides](#reference-guides)
17
- [Best Practices](#best-practices)
18
19
## Overview
20
21
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.
22
23
## When to Use
24
25
- Implementing file upload features
26
- Managing user-uploaded documents
27
- Storing and serving media files
28
- Implementing profile picture uploads
29
- Building document management systems
30
- Handling bulk file imports
31
32
## Quick Start
33
34
Minimal working example:
35
36
```python
37
# config.py
38
import os
39
40
class Config:
41
MAX_CONTENT_LENGTH = 50 * 1024 * 1024 # 50 MB
42
UPLOAD_FOLDER = 'uploads'
43
ALLOWED_EXTENSIONS = {'txt', 'pdf', 'png', 'jpg', 'jpeg', 'gif', 'docx', 'doc'}
44
UPLOAD_DIRECTORY = os.path.join(os.path.dirname(__file__), UPLOAD_FOLDER)
45
46
# file_service.py
47
import os
48
import mimetypes
49
import hashlib
50
import secrets
51
from werkzeug.utils import secure_filename
52
from datetime import datetime
53
import magic
54
import aiofiles
55
56
class FileUploadService:
57
def __init__(self, upload_dir, allowed_extensions, max_size=50*1024*1024):
58
self.upload_dir = upload_dir
59
self.allowed_extensions = allowed_extensions
60
self.max_size = max_size
61
self.mime = magic.Magic(mime=True)
62
// ... (see reference guides for full implementation)
63
```
64
65
## Reference Guides
66
67
Detailed implementations in the `references/` directory:
68
69
| Guide | Contents |
70
|---|---|
71
| [Python/Flask File Upload](references/pythonflask-file-upload.md) | Python/Flask File Upload |
72
| [Node.js Express File Upload with Multer](references/nodejs-express-file-upload-with-multer.md) | Node.js Express File Upload with Multer |
73
| [FastAPI File Upload](references/fastapi-file-upload.md) | FastAPI File Upload |
74
| [S3/Cloud Storage Integration](references/s3cloud-storage-integration.md) | S3/Cloud Storage Integration |
75
76
## Best Practices
77
78
### ✅ DO
79
80
- Validate file extensions and MIME types
81
- Check file size before processing
82
- Use secure filenames to prevent directory traversal
83
- Store files outside web root
84
- Implement virus scanning
85
- Use CDN for file delivery
86
- Generate signed URLs for direct access
87
- Log file upload/download events
88
- Implement access control checks
89
- Clean up temporary files
90
91
### ❌ DON'T
92
93
- Trust user-provided filenames
94
- Store files in web-accessible directories
95
- Allow arbitrary file types
96
- Skip virus scanning for uploaded files
97
- Expose absolute file paths
98
- Allow unlimited file sizes
99
- Ignore access control
100
- Use predictable file paths
101
- Store sensitive metadata in filenames
102
- Forget to validate file content
103

© AJ Geddes · MIT · source · posted by @OpenSourceBuffGuy on promptparty.com

@OpenSourceBuffGuy

I find openly licensed prompts and post them here.

0 followers · 14,621 prompts

More by @OpenSourceBuffGuy

See all
Sea turtle carrying floating film studio island prompt image

Sea turtle carrying floating film studio island

Draws a giant sea turtle carrying a floating island film studio through a starry sky, where fairies polish rough film strips into golden film.

image-prompt, nano-banana, 3d-render, cartoon, fantasy-world, creatures, animals, whimsical, dreamy, cinematic, dramatic-lighting, vibrant-colors, bokeh, miniature, widescreen, night-scene, illustration, concept-art, surreal, storytelling, clay-3d

Desert buggy escapes drones past industrial outpost prompt image

Desert buggy escapes drones past industrial outpost

Builds a 15-second desert chase video where a racer in an armored buggy escapes drones past an industrial outpost, using five reference images with set jobs.

video-prompt, hailuo, action, multi-shot, timed-beats, camera-movement, reference-image, character-consistency, negative-prompt, cinematic, sci-fi, cars, landscape, aerial-view, tracking-shot, photorealistic, sound-effects, structured-output, long-form, widescreen

1 view
Cozy Pixel Art Farm Island Village prompt image

Cozy Pixel Art Farm Island Village

Draws a cozy 16-bit pixel-art farming village across six small islands joined by bridges, with exact counts for buildings, animals and crops.

image-prompt, gpt-image, pixel-art, isometric, game-assets, concept-art, maps, worldbuilding, cozy, vibrant-colors, ocean, landscape, wide-shot, widescreen, game-development, video-games, structured-output, whimsical, summer, high-angle, aerial-view, animals, negative-prompt, cityscape

1 view

Reviews

Loading reviews…

Discussion

Loading comments…