# Base64 Encoder & Decoder – Image, PDF & File to Base64 (`gazidev/base64-file-converter`) Actor

Convert files, images, PDFs and text to Base64, base64url or data URI, and decode Base64 back to files or text. Bulk URLs, Dropbox/Drive links, MIME detection, optional image resize for LLM vision payloads. $0.80 per 1,000 files.

- **URL**: https://apify.com/gazidev/base64-file-converter.md
- **Developed by:** [Cemal Atakli](https://apify.com/gazidev) (community)
- **Stats:** 3 total users, 2 monthly users, 100.0% runs succeeded, 0 bookmarks
- **User rating**: No ratings yet

## Pricing

from $0.80 / 1,000 file converteds

This Actor is paid per event. You are not charged for the Apify platform usage, but only a fixed price for specific events.

Learn more: https://docs.apify.com/actors/running/actors-in-store.md#pay-per-event

## What's an Apify Actor?

An Actor is a serverless cloud program that runs on the Apify platform. It has two run modes.
In Batch mode, an Actor accepts a well-defined JSON input, performs an action which can take anything from a few seconds to a few hours,
and optionally produces a well-defined JSON output, datasets with results, or files in key-value store.
In Standby mode, an Actor provides a web server which can be used as a website, API, or an MCP server.

Apify vocabulary and the platform model are defined once, in the agent quickstart at https://apify.com/agents.md.

## How to integrate an Actor?

If asked about integration, you help developers integrate Actors into their projects.
You adapt to their stack and deliver integrations that are safe, well-documented, and production-ready.

Do not guess an integration path. Every one of them is in the agent quickstart at https://apify.com/agents.md: the Apify MCP server, Agent Skills with the Apify CLI, the JavaScript and Python clients, the REST API, and the account-free path for an agent with no human to sign in. It also carries the rule on stating cost before the first paid run.

For examples already wired to this Actor's own input schema, see the [API](#api) section below.

Each client library has reference documentation the quickstart does not restate: [JavaScript/TypeScript](https://docs.apify.com/api/client/js/docs.md) (`npm install apify-client`) and [Python](https://docs.apify.com/api/client/python/docs.md) (`pip install apify-client`).

# README

## Base64 Encoder & Decoder – Image, PDF & File to Base64 / Data URI and Back

Convert **any file to Base64** in bulk: images, PDFs, documents, audio or plain text. Get standard **Base64**, URL-safe **base64url** or a ready-to-paste **data URI** (`data:image/png;base64,...`). It also works the other way: **decode Base64 or data URIs back into files or text**, with the file type detected for you.

Built for automation: n8n, Make, Zapier and AI-agent workflows that need a data URI for an **LLM vision API**, an email attachment, a JSON payload or an HTML/CSS embed. **$0.80 per 1,000 files, $0.20 per 1,000 texts.** Failed and blocked inputs are free.

### What it does

- **Encode file URLs** (direct links, Dropbox, Google Drive and GitHub share links are turned into direct downloads) and **plain text** (UTF-8).
- **Three output formats:** standard Base64 (optionally wrapped at 76 characters, MIME style), base64url (URL-safe, no padding) and data URI with the detected MIME type.
- **MIME detection from the file content**, not just the extension or server header: PNG, JPEG, WebP, AVIF, GIF, SVG, PDF, ZIP, MP3, MP4 and more.
- **Optional image resize before encoding**, e.g. max 1024 px, and re-encode as JPEG/PNG/WebP. This keeps LLM vision payloads and data URIs small. EXIF rotation is applied.
- **Decode** standard Base64, base64url (with or without padding) and data URIs (also percent-encoded `data:,Hello%20World`). Whitespace and line breaks are ignored. Text and JSON come back as text; images, PDFs and other binaries are saved as **downloadable files** with the correct extension.
- **Large outputs are handled for you:** outputs up to `inlineMaxKb` (default 256 KB) are returned in the dataset row; bigger ones are saved as a `.txt` record in the key-value store and the row gets a `fileUrl`.
- **Every row has** file name, MIME type, input and output size and a **SHA-256** checksum.
- **Safe and clear errors:** web pages returned instead of files, HTTP errors, files over the size limit, private network addresses and social/video platform links (YouTube, TikTok, Instagram…, whose terms forbid downloading) each give a free error row. One bad input never stops the run.

### Use cases

- Send images to **OpenAI, Claude or Gemini vision APIs** as data URIs from a no-code workflow.
- Embed logos and icons in **HTML emails, CSS or JSON** configs.
- Attach PDFs to APIs that only accept Base64 (invoicing, e-signature, email-sending APIs).
- **Decode Base64 attachments** from webhooks or API responses back into real files.
- Check a file's checksum and MIME type in bulk.

### Input example

```json
{
  "mode": "encode",
  "fileUrls": ["https://example.com/photo.jpg", "https://www.dropbox.com/scl/fi/abc/invoice.pdf?dl=0"],
  "outputFormat": "dataUri",
  "resizeMaxPx": 1024
}
```

Decode:

```json
{ "mode": "decode", "base64Inputs": ["SGVsbG8sIEFwaWZ5IQ==", "data:application/pdf;base64,JVBERi0xLjQK..."] }
```

### Output example

```json
{
  "status": "ok", "type": "file", "input": "https://apify.com/img/apify-logo/logomark-32x32.svg",
  "fileName": "logomark-32x32.svg", "mimeType": "image/svg+xml", "inputSizeBytes": 688, "outputSizeBytes": 946,
  "sha256": "5c1f…", "outputFormat": "dataUri",
  "output": "data:image/svg+xml;base64,PHN2ZyB3aWR0aD0iMzIiIGhl…", "charged": true
}
```

A decoded binary file:

```json
{ "status": "ok", "type": "decode", "mimeType": "application/pdf", "decodedSizeBytes": 15214,
  "fileName": "decoded-0003.pdf", "fileUrl": "https://api.apify.com/v2/key-value-stores/<id>/records/decoded-0003.pdf" }
```

The `OUTPUT` record summarises the run: files and texts converted, failures and megabytes processed.

### Pricing (pay per event)

| Event | Price |
|---|---|
| File converted (encode or decode, up to 10 MB) | **$0.0008** |
| Text converted (encode text, or decode to text) | **$0.0002** |
| Each further started 10 MB of a large file | $0.0015 |
| Actor start | $0.00005 |

Errors, blocked URLs and skipped files are **free**. Set a *maximum cost per run* and the Actor stops cleanly at that limit.

| Actor | Per file | Per text |
|---|---|---|
| **This Actor** | **$0.0008** | **$0.0002** |
| eliai/base64-encoder-decoder | $0.002 | $0.001 |

Competitor prices are from the Apify Store on 2026-10-18.

### FAQ

**What is the size limit?** 25 MB per file by default (`maxFileSizeMb`, up to 500 MB). Base64 output is about 33% larger than the file.

**Why did my Google Drive link fail?** The file must be shared as "Anyone with the link". Private links return a sign-in page, which the Actor reports as a free error.

**Can I get the output without the `data:` prefix?** Yes, choose `base64` or `base64url`.

**Is my data stored?** Only in your own run's dataset and key-value store, which follow your Apify data retention settings.

### Use with AI agents (Apify MCP)

This Actor works as a tool in the [Apify MCP server](https://mcp.apify.com). An agent can call it to turn an image URL into a data URI for a vision model, or to decode a Base64 attachment into a downloadable file.

# Actor input Schema

## `mode` (type: `string`):

Encode turns files or text into Base64. Decode turns Base64 strings or data URIs back into files or text.

## `fileUrls` (type: `array`):

Direct links to any file: images, PDFs, documents, audio. Dropbox, Google Drive and GitHub share links are converted to direct downloads. Social/video platforms are not supported.

## `texts` (type: `array`):

Plain text strings to encode (UTF-8).

## `base64Inputs` (type: `array`):

Standard Base64, base64url (with or without padding) or data URIs such as data:image/png;base64,iVBOR... Line breaks and spaces are ignored.

## `outputFormat` (type: `string`):

Data URIs include the detected MIME type and can be pasted into HTML, CSS, JSON or LLM vision APIs.

## `decodeOutput` (type: `string`):

Decoded files are saved in the key-value store with a download link in the row.

## `resizeMaxPx` (type: `integer`):

0 = keep the original size. Example: 1024 shrinks large photos before encoding, which keeps LLM vision payloads small. SVG and GIF are never resized.

## `imageFormat` (type: `string`):

Only used when resizing or when a format other than 'keep' is chosen.

## `imageQuality` (type: `integer`):

Quality for JPEG and WebP output (30-100).

## `inlineMaxKb` (type: `integer`):

Outputs up to this size are returned inside the dataset row (field 'output'). Larger outputs are saved as a .txt record in the key-value store and the row gets a 'fileUrl'.

## `alwaysSaveFile` (type: `boolean`):

Also save small outputs to the key-value store.

## `lineLength` (type: `integer`):

0 = one line. 76 gives MIME / email style lines. Only for standard Base64.

## `maxFileSizeMb` (type: `integer`):

Larger files are skipped with a free error row.

## `rejectHtml` (type: `boolean`):

When a URL returns an HTML page instead of a file (for example a private share link), return a free error row instead of encoding the page.

## Actor input object example

```json
{
  "mode": "encode",
  "fileUrls": [
    "https://apify.com/img/apify-logo/logomark-32x32.svg"
  ],
  "outputFormat": "base64",
  "decodeOutput": "auto",
  "resizeMaxPx": 0,
  "imageFormat": "keep",
  "imageQuality": 85,
  "inlineMaxKb": 256,
  "alwaysSaveFile": false,
  "lineLength": 0,
  "maxFileSizeMb": 25,
  "rejectHtml": true
}
```

# Actor output Schema

## `results` (type: `string`):

No description

## `files` (type: `string`):

No description

## `summary` (type: `string`):

No description

# API

You can run this Actor programmatically using our API. Below are code examples in JavaScript, Python, and CLI, as well as the OpenAPI specification and MCP server setup.

## JavaScript example

```javascript
import { ApifyClient } from 'apify-client';

// Initialize the ApifyClient with your Apify API token
// Replace the '<YOUR_API_TOKEN>' with your token
const client = new ApifyClient({
    token: '<YOUR_API_TOKEN>',
});

// Prepare Actor input
const input = {
    "fileUrls": [
        "https://apify.com/img/apify-logo/logomark-32x32.svg"
    ]
};

// Run the Actor and wait for it to finish
const run = await client.actor("gazidev/base64-file-converter").call(input);

// Fetch and print Actor results from the run's dataset (if any)
console.log('Results from dataset');
console.log(`💾 Check your data here: https://console.apify.com/storage/datasets/${run.defaultDatasetId}`);
const { items } = await client.dataset(run.defaultDatasetId).listItems();
items.forEach((item) => {
    console.dir(item);
});

// 📚 Want to learn more 📖? Go to → https://docs.apify.com/api/client/js/docs

```

## Python example

```python
from apify_client import ApifyClient

# Initialize the ApifyClient with your Apify API token
# Replace '<YOUR_API_TOKEN>' with your token.
client = ApifyClient("<YOUR_API_TOKEN>")

# Prepare the Actor input
run_input = { "fileUrls": ["https://apify.com/img/apify-logo/logomark-32x32.svg"] }

# Run the Actor and wait for it to finish
run = client.actor("gazidev/base64-file-converter").call(run_input=run_input)

# Fetch and print Actor results from the run's dataset (if there are any)
print(f"💾 Check your data here: https://console.apify.com/storage/datasets/{run.default_dataset_id}")
for item in client.dataset(run.default_dataset_id).iterate_items():
    print(item)

# 📚 Want to learn more 📖? Go to → https://docs.apify.com/api/client/python/docs/quick-start

```

## CLI example

```bash
echo '{
  "fileUrls": [
    "https://apify.com/img/apify-logo/logomark-32x32.svg"
  ]
}' |
apify call gazidev/base64-file-converter --silent --output-dataset

```

## MCP server setup

```json
{
    "mcpServers": {
        "apify": {
            "type": "http",
            "url": "https://mcp.apify.com/?tools=fetch-actor-details,gazidev/base64-file-converter"
        }
    }
}
```

The hosted server signs you in with OAuth on first connect, so no API token belongs in this config. Clients without OAuth support can send an `Authorization: Bearer <APIFY_API_TOKEN>` header instead, using a token from API & Integrations in Apify Console (https://console.apify.com/settings/integrations).

## OpenAPI specification

Download the OpenAPI definition: https://api.apify.com/v2/actors/h4e9dJmhZHYfLcryD/builds/fJaSUCuaG1FvywvF7/openapi.json
