File to Base64 & Data URI Generator

Convert PDF documents, ZIP archives, JSON, audio, video, or any binary file into standard Base64 strings and RFC 2397 Data URIs with drag & drop uploader.

Choose a file or drag & drop here Supports PDF, ZIP, Audio, Video, JSON, TXT & Binary (Max 10MB)
Encoded file details and Data URI will appear here in real time...

How to Convert Any File to Base64 Online

1

Upload File or Paste Data

Drag and drop your file (PDF, ZIP, JSON, audio, binary) or paste text content into the upload zone.

2

Configure MIME & URL-Safe Options

Confirm the target MIME type and optionally toggle URL-safe encoding in real time.

3

Copy Base64 or Data URI

The tool encodes automatically in real time. Copy the Complete Data URI or Raw Base64 string with 1 click.

Tool Features

Client-Side FileReader

Converts large files up to 10MB completely in your browser without uploading sensitive files to servers.

RFC 2397 Data URIs

Automatically formats RFC-compliant data:[mime];base64,... strings ready for immediate embedding.

1-Click Export to .TXT

Download the full encoded Base64 string as a standalone text file for CI/CD and script automation.

Your Data Privacy

Web Tool
Privacy-First Architecture
Most of our web tools process your data entirely in-browser. Where server processing is technically required, payloads are evaluated statelessly in-memory and are never stored, saved, or logged.
REST API
Stateless In-Memory Processing
When you use our API endpoints, your requests are processed strictly in-memory without persistent database storage, disk logging, or data retention.
Want to learn more about how we safeguard your information and infrastructure?
Read our full Privacy Policy for detailed security standards, data retention principles, and compliance guarantees.

What does the File to Base64 & Data URI Generator do?

The File to Base64 Generator converts any binary or text file (including PDF documents, ZIP archives, JSON payloads, audio clips, video clips, and plain text files) into standard Base64 encoded strings and RFC 2397 Data URIs (data:[mime];base64,...).

All encoding executes with maximum privacy in your browser memory or via high-performance microservice endpoints.

Core Concepts

  • RFC 2397 Data URI Scheme: Data URIs allow binary content to be embedded inline in HTML, CSS stylesheets, JavaScript files, or JSON API payloads without secondary HTTP requests.
  • Client-Side Privacy: Browser-based file decoding prevents confidential documents, client assets, and proprietary binaries from ever touching remote servers.
  • URL-Safe Encoding Mode: Converts standard Base64 + and / characters to - and _ with padding removal (=), making strings safe for URL query parameters, REST path segments, and JWT payloads.

How to use the tool?

  1. Upload File or Paste Data: Drag and drop your file (PDF, ZIP, JSON, audio, binary) into the drop zone, click Browse, or click Sample.
  2. Configure MIME & URL-Safe Options: Choose your target MIME type or toggle URL-safe Base64 mode from the top master toolbar.
  3. Instant Real-Time Result: The tool encodes in real time. Inspect file metrics and copy the Complete Data URI or Raw Base64 string.

Related Developer Utilities

  • Base64 to File: Convert Base64 strings and Data URIs back into downloadable binary files.
  • Image to Base64: Encode image files with dedicated canvas previews and CSS/HTML export snippets.
  • Base64 to Image: Decode Base64 strings into downloadable PNG, JPEG, SVG, WebP, and GIF images.
  • Base64 Encoder: Encode plain text strings into standard or URL-safe Base64.

REST API Integration

blueutils.com provides a free REST API endpoint (POST https://blueutils.com/api/base64/file-to-base64) for programmatic encoding in CI/CD pipelines and backend microservices.

API Request Parameters

Name Type Description Example
rawText String / Object Raw file content, Buffer, or text (aliases: text, payload, data, input, value). "Hello World"
filename String Optional filename for MIME detection and metadata tracking. "document.pdf"
mimeType String Target MIME type (e.g. application/pdf, application/zip). "application/pdf"
isUrlSafe Boolean If true, replaces + with - and / with _, stripping =. true
isAlreadyBase64 Boolean Set to true if rawText is already Base64 to be wrapped into a Data URI. false

API Request Payload Examples

cURL

curl -X POST https://blueutils.com/api/base64/file-to-base64 \
  -H "Content-Type: application/json" \
  -d '{ "rawText": "{\"status\":\"ok\"}", "mimeType": "application/json", "filename": "config.json" }'

Python

import requests

url = "https://blueutils.com/api/base64/file-to-base64"
payload = {
    "rawText": "{\"status\":\"ok\"}",
    "mimeType": "application/json",
    "filename": "config.json"
}
headers = {"Content-Type": "application/json"}
response = requests.post(url, json=payload, headers=headers)
print(response.json())

Java

import java.net.URI;
import java.net.http.HttpClient;
import java.net.http.HttpRequest;
import java.net.http.HttpResponse;

public class Main {
    public static void main(String[] args) throws Exception {
        String jsonPayload = "{\"rawText\": \"{\\\"status\\\":\\\"ok\\\"}\", \"mimeType\": \"application/json\"}";
        HttpClient client = HttpClient.newHttpClient();
        HttpRequest request = HttpRequest.newBuilder()
            .uri(URI.create("https://blueutils.com/api/base64/file-to-base64"))
            .header("Content-Type", "application/json")
            .POST(HttpRequest.BodyPublishers.ofString(jsonPayload))
            .build();
        HttpResponse<String> response = client.send(request, HttpResponse.BodyHandlers.ofString());
        System.out.println(response.body());
    }
}

API Response Parameters

Name Type Description Example
isValid Boolean Indicates whether file encoding succeeded. true
dataUri String Complete RFC 2397 Data URI. "data:application/json;base64,..."
base64 String Raw Base64 payload without scheme. "eyJzdGF0dXMiOiJvayJ9"
filename String Resolved filename. "config.json"
mimeType String Applied MIME type. "application/json"
byteLength Number Decoded binary size in bytes. 15
formattedSize String Human-readable byte size. "15 B"

API Response Payload Examples

Success Response (HTTP 200 OK)

{
  "isValid": true,
  "dataUri": "data:application/json;base64,eyJzdGF0dXMiOiJvayJ9",
  "base64": "eyJzdGF0dXMiOiJvayJ9",
  "filename": "config.json",
  "mimeType": "application/json",
  "byteLength": 15,
  "formattedSize": "15 B"
}

Validation Failure Response (HTTP 400 Bad Request)

{
  "isValid": false,
  "error": "Invalid input: File payload cannot be empty."
}

Rate Limit Exceeded Response (HTTP 429 Too Many Requests)

{
  "error": "API rate limit exceeded. Please wait or contact support@blueutils.com."
}

Native Usage

Encode files to Base64 strings locally on your computer using native CLI utilities:

Windows (PowerShell)

# Convert file to Base64 string in PowerShell
$bytes = [System.IO.File]::ReadAllBytes("document.pdf")
$b64 = [System.Convert]::ToBase64String($bytes)
Write-Output "data:application/pdf;base64,$b64"

Linux / Unix (Bash)

# Convert file to Base64 in Bash
base64 -w 0 document.pdf > document_base64.txt

Python

import base64

with open("document.pdf", "rb") as f:
    b64_str = base64.b64encode(f.read()).decode("utf-8")
print(f"data:application/pdf;base64,{b64_str}")

Java

import java.nio.file.Files;
import java.nio.file.Path;
import java.util.Base64;

public class FileToBase64 {
    public static void main(String[] args) throws Exception {
        byte[] bytes = Files.readAllBytes(Path.of("document.pdf"));
        String b64 = Base64.getEncoder().encodeToString(bytes);
        System.out.println("data:application/pdf;base64," + b64);
    }
}

Frequently Asked Questions (FAQ)

How do I convert a file to Base64 online?

Drag and drop any file (PDF, ZIP, JSON, audio, etc.) or paste text content into the editor and click Convert to Base64. The tool generates a Complete Data URI and raw Base64 string.

Is there a file size limit?

Blueutils supports file uploads up to 5MB completely in-browser using the native FileReader API.

Are my files stored or uploaded to remote servers?

No. All file reading, Base64 conversion, and text generation execute 100% locally on your computer inside your browser.

Rate Limits

UI Limits
100 uses per 15 minutes
Max payload size: 5 MB
API Limits
5 requests per 60 minutes
Max payload size: 256 KB
Need higher API rate limits, increased payload sizes, or custom developer solutions?
Contact our engineering team at support@blueutils.com for custom rate limit increases, higher quota allocations, or tailored enterprise integrations.