# Base64 Encoder & Decoder: Files, Images & Text to Data URI (`pikoulas/base64-encoder`) Actor

Encode text, or any file or image by URL, to Base64 and a data: URI; decode Base64, base64url or data URIs back to text or a downloadable file. Batch input, the file type detected, URL-safe alphabet. Failed items are free.

- **URL**: https://apify.com/pikoulas/base64-encoder.md
- **Developed by:** [Spyridon Pikoulas](https://apify.com/pikoulas) (community)
- **Categories:** Developer tools, Automation, Integrations
- **Features:** Limited permissions
- **Stats:** 2 total users, 1 monthly users, 100.0% runs succeeded, 0 bookmarks
- **User rating**: No ratings yet

## Pricing

from $0.80 / 1,000 texts

This Actor is paid per event. You are not charged for the Apify platform usage, but only a fixed price for specific events.
Since this Actor supports Apify Store discounts, the price gets lower the higher subscription plan you have.

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: Files, Images & Text to Data URI

Encode text, or any file or image by URL, to Base64 and a ready `data:` URI; decode Base64 back to
text or the original file. A row per item, so a list of a thousand goes in one run:

- **Encode texts**: each text's UTF-8 bytes as Base64, in the standard alphabet or base64url.
- **Encode files by URL**: images, PDFs, documents, audio, anything up to 100 MB, with the Base64,
  a `data:` URI to paste into `<img src>`, CSS or an email, and the file's type read from its bytes.
- **Decode**: Base64, base64url (with or without `=` padding) or a `data:` URI back to its text, or,
  for an image, a PDF or any binary, to a file with a download link.

It costs **$0.80 per 1,000 texts** and **$1.60 per 1,000 files**. Items that fail are free.

### What people use it for

- **APIs and webhooks:** an image or PDF as Base64 inside a JSON payload, or the file inside a
  Base64 attachment someone sent.
- **HTML, CSS and email templates:** images inlined as `data:` URIs.
- **Make, Zapier and n8n:** encoding or decoding as one hosted step between two apps.
- **AI agents:** a file as Base64 for a model's input, or a model's Base64 output as a file.

### How to encode a file to Base64

1. Click **Try for free**; Apify's free plan covers a first run.
2. Pick **Encode** or **Decode**, and add **Texts** or **File URLs**.
3. Click **Start**, then download the results as JSON, CSV, Excel or HTML, or read them through
   the API.

An input with more options:

```json
{
  "mode": "encode",
  "texts": ["Hello from Apify!"],
  "urls": ["https://www.python.org/static/img/python-logo.png"],
  "urlSafe": false,
  "maxFileSizeMb": 25
}
```

### Output

A file encoded:

```json
{
  "mode": "encode",
  "url": "https://www.python.org/static/img/python-logo.png",
  "finalUrl": "https://www.python.org/static/img/python-logo.png",
  "fileName": "python-logo.png",
  "contentType": "image/png",
  "inputBytes": 15770,
  "alphabet": "standard",
  "base64": "iVBORw0KGgoAAAANSUhEUgAAAkQAAACkCAYAAAB2OzHx...",
  "dataUri": "data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAkQAAACkCAYAAAB2OzHx...",
  "base64Url": null,
  "processedAt": "2026-11-20T21:54:55Z",
  "error": null
}
```

A Base64 string decoded:

```json
{
  "mode": "decode",
  "input": "SGVsbG8sIHdvcmxkIQ==",
  "kind": "text",
  "contentType": "text/plain",
  "decodedBytes": 13,
  "text": "Hello, world!",
  "textUrl": null,
  "fileUrl": null,
  "processedAt": "2026-11-20T21:54:57Z",
  "error": null
}
```

A row holds up to 3 MB of Base64 or text; past that, `base64Url` or `textUrl` links the whole of it
in the run's key-value store. A decoded image, PDF or other binary is always a file at `fileUrl`;
decoded text is too with **Decoded text as a file too**. `contentType` is the type a `data:` URI
declares, or else the one read from the file's first bytes and name (PNG, JPEG, GIF, WebP, AVIF,
SVG, PDF, ZIP and Office files, MP3, MP4, WAV and more). A failed item has its reason in `error`.

### Use it as an API

One call runs it and returns the results as JSON (for runs under 5 minutes; longer ones start a
run and read its dataset). Apify's Python and JavaScript clients, and its Make, Zapier and n8n
integrations, work the same way.

```bash
curl -X POST "https://api.apify.com/v2/acts/pikoulas~base64-encoder/run-sync-get-dataset-items?token=YOUR_APIFY_TOKEN" \
  -H "Content-Type: application/json" \
  -d '{"urls": ["https://www.python.org/static/img/python-logo.png"]}'
```

AI agents can call it as a tool through Apify's MCP server: `https://mcp.apify.com?tools=pikoulas/base64-encoder`.

### How much does it cost to encode files to Base64?

You pay **$0.0008 per text** encoded or decoded and **$0.0016 per file** downloaded and encoded,
$0.80 and $1.60 per 1,000, on Apify's paid plans, and $1.20 and $2.40 per 1,000 on the free plan.
Items that fail aren't charged. There are no monthly fees. Set a spending limit on a run and it
stops there with what it has.

### Good to know

- Files are downloaded as a guest of each website: it says who it is, keeps to the site's
  robots.txt, waits a second between requests to one site, and leaves a site that refuses alone.
  Private and local network addresses aren't read.
- Decoding takes both alphabets, ignores line breaks and spaces, and adds missing `=` padding.
- The `data:` URI always uses the standard alphabet, as browsers expect, even with **URL-safe
  alphabet** on.

### FAQ

#### Is Base64 encryption?

No: anyone can decode it. It makes binary data safe to carry as text, in JSON, URLs, HTML or email.

#### Something missing or not working?

Open an issue on the **Issues** tab with the input you used, or ask there for a field you need.

If it does what you need, a review on the **Reviews** tab helps others find it.

# Actor input Schema

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

Encode turns texts and files into Base64; decode turns Base64 strings back into text or a file.

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

Texts to encode, or in decode mode Base64 strings to decode: standard, base64url or a data URI (data:image/png;base64,...). Each is a row of its own.

## `urls` (type: `array`):

Files or images to download and encode (encode mode): each row has the Base64, a data: URI and the file's type.

## `urlSafe` (type: `boolean`):

Encode with - and \_ instead of + and /, without = padding (RFC 4648, section 5). Decoding takes both alphabets either way; the data URI keeps the standard one.

## `decodeToFile` (type: `boolean`):

Decode mode: also store decoded text as a file with a download URL. Decoded binary (images, PDFs, archives) is always stored as a file.

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

Files larger than this aren't downloaded; their row says so and isn't charged.

## Actor input object example

```json
{
  "mode": "encode",
  "texts": [
    "Hello from Apify!"
  ],
  "urlSafe": false,
  "decodeToFile": false,
  "maxFileSizeMb": 20
}
```

# Actor output Schema

## `overview` (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 = {
    "texts": [
        "Hello from Apify!"
    ],
    "maxFileSizeMb": 20
};

// Run the Actor and wait for it to finish
const run = await client.actor("pikoulas/base64-encoder").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 = {
    "texts": ["Hello from Apify!"],
    "maxFileSizeMb": 20,
}

# Run the Actor and wait for it to finish
run = client.actor("pikoulas/base64-encoder").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 '{
  "texts": [
    "Hello from Apify!"
  ],
  "maxFileSizeMb": 20
}' |
apify call pikoulas/base64-encoder --silent --output-dataset

```

## MCP server setup

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

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/rW4cV2wYo2HaZJS2N/builds/a4m5IlSoNnBVdI3bn/openapi.json
