Base64 to File Converter
Decode a Base64 string and download it as a file. Supports all file types with automatic MIME type detection and custom filenames.
Paste a Base64 string (with or without a data: prefix) and download it as a file. The MIME type is auto-detected from data URIs.
Base64 to File in Code
Decode Base64 strings and save them as files programmatically.
import base64
# Decode Base64 string to file
def base64_to_file(b64: str, output_path: str):
# Strip data URI prefix if present
if "," in b64:
b64 = b64.split(",", 1)[1]
with open(output_path, "wb") as f:
f.write(base64.b64decode(b64))
# Usage
base64_to_file("iVBORw0KGgo...", "image.png")
# Decode with MIME type detection
def base64_to_file_safe(b64: str, output_path: str):
import re
# Extract MIME type from data URI
mime_match = re.match(r"data:([^;]+)", b64)
if mime_match:
mime = mime_match.group(1)
print(f"Detected MIME: {mime}")
if "," in b64:
b64 = b64.split(",", 1)[1]
with open(output_path, "wb") as f:
f.write(base64.b64decode(b64))Frequently Asked Questions
Search below or browse through our most commonly asked questions.
Related Tools
Base64 Converter
Encode text to Base64 or decode Base64 to text — all in one tool
File to Base64
Convert any file (PDF, image, audio, doc) to a Base64 string instantly in your browser
Base64 to PDF Converter
Convert Base64 strings directly into downloadable PDF files with instant preview
Base64 to Image
Decode Base64 strings into images instantly. Live preview your image and download the raw file
Base64 Analyzer
Analyze Base64 strings to determine their validity, character set, padding, length, and decoded data type