A simple Flask API that converts base64-encoded data to binary format, primarily designed for audio file processing.
- Convert base64-encoded data to binary format
- Support for any MIME type
- Health check endpoint
- Docker support for easy deployment
- Compatible with ngrok for tunneling
Converts base64 data to binary format.
Request Body:
{
"base64_data": "data:audio/mp3;base64,SGVsbG8gV29ybGQ=",
"mimetype": "audio/mp3"
}Response: Binary data with the specified MIME type
Health check endpoint.
Response:
{
"status": "API running",
"endpoint": "/decode"
}- Python 3.11+
- Flask 2.3.3
- Docker (optional)
- ngrok (for tunneling)
-
Install Python dependencies:
pip install -r requirements.txt
-
Run the application:
python app.py
The API will be available at http://localhost:5001
-
Build and run with Docker Compose:
docker-compose up --build
-
Or build and run with Docker directly:
docker build -t base64-converter . docker run -p 5001:5001 base64-converter
The API will be available at http://localhost:5001
To expose your local API to the internet using ngrok:
- Install ngrok:
- Visit ngrok.com and create an account
- Download and install ngrok for your operating system
- Authenticate ngrok with your authtoken:
ngrok authtoken YOUR_AUTHTOKEN
-
Start your application (either locally or with Docker) on port 5001
-
In a new terminal, create an ngrok tunnel:
ngrok http 5001
-
ngrok will provide you with public URLs like:
Forwarding http://abc123.ngrok.io -> http://localhost:5001 Forwarding https://abc123.ngrok.io -> http://localhost:5001 -
Use the HTTPS URL for secure connections:
https://abc123.ngrok.io
curl -X POST https://your-ngrok-url.ngrok.io/decode \
-H "Content-Type: application/json" \
-d '{
"base64_data": "SGVsbG8gV29ybGQ=",
"mimetype": "text/plain"
}'curl -X POST http://localhost:5001/decode \
-H "Content-Type: application/json" \
-d '{
"base64_data": "data:audio/mp3;base64,YOUR_BASE64_DATA_HERE",
"mimetype": "audio/mp3"
}' \
--output converted_audio.mp3curl http://localhost:5001/- Build image:
docker build -t base64-converter . - Run container:
docker run -p 5001:5001 base64-converter - Run with Docker Compose:
docker-compose up --build - Stop Docker Compose:
docker-compose down
- The API removes data URL prefixes automatically (e.g.,
data:audio/mp3;base64,) - All errors return JSON with an
errorfield - The application runs in debug mode by default for development
- For production deployment, consider using a WSGI server like Gunicorn