
- Set up FastAPI project structure - Implement database models and migrations for file metadata - Create file upload endpoint with size validation - Implement file download and listing functionality - Add health check and API information endpoints - Create comprehensive documentation
34 lines
847 B
Python
34 lines
847 B
Python
from pathlib import Path
|
|
|
|
from pydantic_settings import BaseSettings
|
|
|
|
|
|
class Settings(BaseSettings):
|
|
PROJECT_NAME: str = "File Upload Download API"
|
|
API_V1_STR: str = "/api/v1"
|
|
|
|
# Base directory for storage
|
|
STORAGE_DIR: Path = Path("/app/storage")
|
|
|
|
# File storage directory
|
|
FILE_STORAGE_DIR: Path = STORAGE_DIR / "files"
|
|
|
|
# Database
|
|
DB_DIR: Path = STORAGE_DIR / "db"
|
|
SQLALCHEMY_DATABASE_URL: str = f"sqlite:///{DB_DIR}/db.sqlite"
|
|
|
|
# Configure max file size (10MB by default)
|
|
MAX_FILE_SIZE: int = 10 * 1024 * 1024 # 10MB in bytes
|
|
|
|
class Config:
|
|
case_sensitive = True
|
|
env_file = ".env"
|
|
|
|
|
|
# Create settings instance
|
|
settings = Settings()
|
|
|
|
# Ensure storage directories exist
|
|
settings.DB_DIR.mkdir(parents=True, exist_ok=True)
|
|
settings.FILE_STORAGE_DIR.mkdir(parents=True, exist_ok=True)
|