A simple FastAPI server for storing and retrieving files.
- Create a virtual environment (recommended):
python -m venv venv
source venv/bin/activate # On Windows: venv\Scripts\activate- Install dependencies:
pip install -r requirements.txtStart the server with:
uvicorn main:app --reloadThe server will start on http://localhost:8000
Retrieve a file by filename.
Example:
curl http://localhost:8000/files/myfile.txtStore a file locally on the filesystem.
Example:
curl -X POST -F "file=@/path/to/your/file.txt" http://localhost:8000/filesList all stored files.
Example:
curl http://localhost:8000/filesHealth check endpoint to verify server status.
Example:
curl http://localhost:8000/healthResponse:
{
"status": "healthy",
"timestamp": "2024-01-01T12:00:00.000000",
"service": "File Storage API"
}Metrics endpoint providing server statistics including file counter and storage usage.
Example:
curl http://localhost:8000/metricsResponse:
{
"files_stored_total": 10,
"files_current": 8,
"total_storage_bytes": 1048576,
"total_storage_mb": 1.0,
"timestamp": "2024-01-01T12:00:00.000000"
}Once the server is running, you can access:
- Interactive API docs: http://localhost:8000/docs
- Alternative API docs: http://localhost:8000/redoc
Files are stored in the storage/ directory, which is created automatically when the server starts.