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?
- Upload File or Paste Data: Drag and drop your file (PDF, ZIP, JSON, audio, binary) into the drop zone, click Browse, or click Sample.
- Configure MIME & URL-Safe Options: Choose your target MIME type or toggle URL-safe Base64 mode from the top master toolbar.
- 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.txtPython
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);
}
}