Skip to content

About

Base64 converter

Resources

Stars

0 stars

Watchers

0 watching

Forks

Latest commit

 

History

1 Commit

Folders and files

Repository files navigation

Base64 Audio Converter API

A simple Flask API that converts base64-encoded data to binary format, primarily designed for audio file processing.

Features

  • 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

API Endpoints

POST /decode

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

GET /

Health check endpoint.

Response:

{
  "status": "API running",
  "endpoint": "/decode"
}

Requirements

  • Python 3.11+
  • Flask 2.3.3
  • Docker (optional)
  • ngrok (for tunneling)

Local Development Setup

Option 1: Direct Python Setup

  1. Install Python dependencies:

    pip install -r requirements.txt
  2. Run the application:

    python app.py

The API will be available at http://localhost:5001

Option 2: Docker Setup

  1. Build and run with Docker Compose:

    docker-compose up --build
  2. 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

ngrok Tunnel Setup

To expose your local API to the internet using ngrok:

Prerequisites

  1. 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

Creating the Tunnel

  1. Start your application (either locally or with Docker) on port 5001

  2. In a new terminal, create an ngrok tunnel:

    ngrok http 5001
  3. ngrok will provide you with public URLs like:

    Forwarding  http://abc123.ngrok.io -> http://localhost:5001
    Forwarding  https://abc123.ngrok.io -> http://localhost:5001
    
  4. Use the HTTPS URL for secure connections: https://abc123.ngrok.io

Testing the Tunneled API

curl -X POST https://your-ngrok-url.ngrok.io/decode \
  -H "Content-Type: application/json" \
  -d '{
    "base64_data": "SGVsbG8gV29ybGQ=",
    "mimetype": "text/plain"
  }'

Usage Examples

Converting Base64 Audio File

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.mp3

Health Check

curl http://localhost:5001/

Docker Commands Reference

  • 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

Notes

  • The API removes data URL prefixes automatically (e.g., data:audio/mp3;base64,)
  • All errors return JSON with an error field
  • The application runs in debug mode by default for development
  • For production deployment, consider using a WSGI server like Gunicorn

About

Base64 converter

Resources

Stars

0 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages