Media Proxy is a Python-based application designed to manage and validate media files. It allows users to upload files and retrieve them through specified endpoints. The application is built using Flask and provides a simple interface for file management, including health checks to ensure the service is running correctly.
- Requirements
- Installation
- Environment Variables
- Running the Application
- Endpoints
- Testing and Code Quality
- Contributing
- Python 3.10
- Docker
- Clone the repository
git clone https://github.com/sashaPost/media_proxy
cd media_proxy - Create a Virtual Environment:
python3 -m venv .venv - Activate the Virtual Environment:
source .venv/bin/activate - Install dependencies:
pip install -r requirements.txt - In the root directory of the project, create a .env file and add your API key:
API_KEY="your_api_key"
Set the following environment variables:
- FLASK_ENV: Set to development.
- FLASK_DEBUG: Set to 1.
- FLASK_HOST: Set to 0.0.0.0.
- FLASK_PORT: Set to 5000.
You can also set all necessary environment variables at once using the provided set_env.sh script:
chmod +x set_env.sh
source ./set_env.sh
- Using Virtual Environment:
flask run - Using Docker
- Build the Docker image:
docker build -t media_proxy . - Run the container:
docker run -p 8080:5000 media_proxy
- Build the Docker image:
- Health Check Endpoint
You can check the health of the application by sending a request to the following endpoint:
curl http://localhost:5000/health - Get Media File
Retrieve a file from the media directory:GET /media/<path:file_path>
- Parameters:
file_path- The path to the requested file relative to the media directory.
- Request Example:
curl http://localhost:5000/media/images/file.jpg
- Success Response:
Returns the requested file. - Error Response:
Returns a 404 error if the file is not found.
{"error": "File not found"}
- Parameters:
- Upload Media File
Upload a file to the media directory:POST /media/<path:origin_file_path>
- Parameters:
origin_file_path- The relative file path intended for the uploaded file.
- Request Example:
curl -X POST \
-H "Authorization: your_api_key" \
-F "file=@/path/to/your/upload_file.jpg" \
http://localhost:5000/media/images/upload_file.jpg
- Success Response:
Returns a message indicating success (200 OK).
{"message": "OK"} - Error Response:
Returns a 501 error if there was an issue during the upload process.
{"error": "Error uploading file"}
- Parameters:
- The project uses coverage for test
coveragereporting.
Run tests with:coverage run -m pytest - pre-commit is configured for managing
pre-commithooks to maintain code quality.
Feel free to contribute to the project by submitting issues or pull requests.