A FastAPI project that handles parsing multipart/form-data for file uploads. It abstracts the storage layer into a repository (storage.py) so you can easily switch between local disk storage (for dev) and AWS S3 (for production). The web frontend features a drag-and-drop HTML5 unified interface to test file creation.
63-fastapi-s3-upload/
main.py # FastAPI Entry point
storage.py # Abstracted Storage layer (Local Disk vs AWS S3)
routes/
files.py # Routes handling file I/O
uploads/ # Local folder storing dev files
index.html # Unified single-file Frontend (Drag and drop)
requirements.txt # Dependencies
README.md # This file
pip install -r requirements.txtuvicorn main:app --reloadOpen index.html directly in your browser. Since it operates completely client-side in terms of layout, you can just click on the file in your OS, no need for http.server.
{
"info": "2 files uploaded successfully",
"filenames": [
"c8a1b2_document.pdf",
"f2e4d9_image.png"
]
}- FastAPI UploadFile / File: Effectively parsing binary files.
aiofiles: Writing binary files to local disk asynchronously so the main event loop isn't blocked.- Repository Pattern: We place the actual "save logic" inside
storage.py. Here we use local disk logic, butboto3for S3 is mentioned so a developer can switch depending on environment variables. - Serving Static Files: Using
fastapi.staticfilesto serve previously uploaded images.