---
updatedAt: 2025-07-15T08:41:43.000Z
agentTools:
  projectIndex: https://docs.appery.io/llms.txt
---

# Binary Data

API Express provides a powerful and flexible mechanism of working with binary data.

API Express uses JSON format so the Base64 format is used to work with binary data (follow [this link](https://en.wikipedia.org/wiki/Base64) to learn more).

For testing, you can use [Base64 Converter](https://www.base64decode.org/) to convert ordinary strings to strings in Base64 format and vise versa.

### API Express provides two types of services: Generated and Custom.

## Binary data in Generated Services

API Express provides embedded support of Binary for Generated services.

1. Fields with type **BLOB** in Generated services are considered as Binary.
2. Operations **GET** and **LIST** will convert the value of this field into a Base64 String.
3. Operations **CREATE** and **UPDATE** will accept String in Base64 format and API Express will save the converted binary into a database.

## Binary data in Custom Services

Binary in custom flow is available for the following cases:

1. Component **START** can accept binary when HTTP type is **POST**, **PUT** or **PATCH** and field **type** in **REQUEST BODY** is **Binary**. Binary value becomes available in flow as **Binary Request**
2. Component **REST** can return binary response when **Is binary** check box is enabled in **RESPONSE BODY** section. Binary value becomes available in flow as **Binary Response**
3. Component REST can accept binary when the HTTP type is set to **POST**, **PUT** or **PATCH** and the **Type** is **Binary** in the **REQUEST BODY** section; also, field **Binary Body** should be mapped on **Binary Request** or **Binary Response**
4. Component **END** can return binary response when check box **Is binary** is selected in **RESPONSE BODY** section and value of **Binary Body** combobox is **Binary request** or **Binary response**

To better understand how it works let’s consider an example:

## Example 1. Binary in Generated services

Relational database has table files with columns **id**, **name**, and **content**:\
**id** - unique identifier of files\
**name** - file name\
**content** - file binary content

The following DDL scripts can be used for

```mysql MySQL
CREATE TABLE files
(
 id      INT          NOT NULL auto_increment PRIMARY KEY,
 name    VARCHAR(64) NOT NULL,
 content BLOB         NOT NULL
)
```
```sql PostgreSQL
CREATE TABLE files
(
 id      SERIAL PRIMARY KEY,
 name    VARCHAR(64) NOT NULL,
 content BYTEA        NOT NULL
);
```
```sql MSSQL
CREATE TABLE dbo.files
(
 id      INT PRIMARY KEY IDENTITY,
 name    VARCHAR(64) NOT NULL,
 content VARBINARY    NOT NULL
)
```
```sql Oracle
CREATE TABLE files
(
 id      INT PRIMARY KEY,
 name    VARCHAR(64) NOT NULL,
 content BLOB         NOT NULL
);
```

It is assumed that the Database Connection to Relational database already exists.\
To work with the table, let’s create an API Express Generated service.

<Image align="center" className="border" border={true} src="https://files.readme.io/bd70b14-Screenshot_2018-05-15_18.46.08.png" />

On the Test page, we can check how our services are working:

1. Create a record in the files table.\
   Name the file ***test.txt***. The file will contain the only sentence *test message*.\
   This content will look like IHRlc3QgbWVzc2FnZQ==  in Base64 format.

```json Request payload
{
    "name": "test.txt",
    "content": "IHRlc3QgbWVzc2FnZQ=="
}
```

Response of operation create

```json Response
{
    "content": "IHRlc3QgbWVzc2FnZQ==",
    "id": 1,
    "name": "test.txt"
}
```

Take a look at this record in the database client and see that the sentence test message has been saved in the database.

<Image align="center" className="border" border={true} src="https://files.readme.io/e8b2146-Screenshot_2018-05-15_18.53.42.png" />

<Image align="center" className="border" border={true} src="https://files.readme.io/50f9e9b-Screenshot_2018-05-15_18.54.04.png" />

2. Get a record from the files table.

The operation **FIND** will return the just created record after the file name has been passed in the query:\
&#x9;

```json
{
    		"name": "test.txt"
}
```

The response of **FIND** operation is

```json
[{
    "content": "IHRlc3QgbWVzc2FnZQ==",
    "id": 1,
    "name": "test.txt"
}]
```

<Image align="center" className="border" border={true} src="https://files.readme.io/86aeda6-Screenshot_2018-05-16_11.25.29.png" />

## Example 2. Custom service accepts Binary and returns it.

1. Create a custom service
2. For the component **START**, specify:\
   a. HTTP type as **POST**\
   b. Select **Binary** (field **Type**) in the **REQUEST BODY** section

<Image align="center" className="border" border={true} src="https://files.readme.io/46261a9-Screenshot_2018-05-16_11.44.22.png" />

3. For the component **END**:\
   a. Enable **Is binary**\
   b. Specify Binary body as Binary request\
   c. Specify Content-Type as ***'application/octet-stream'***

<Image align="center" className="border" border={true} src="https://files.readme.io/8e83814-Screenshot_2018-05-16_13.41.15.png" />

4. Open the Test page
5. Any text which is passed in Body will be returned as it is in Response

<Image align="center" className="border" border={true} src="https://files.readme.io/fa6cfe1-Screenshot_2018-05-16_11.48.34.png" />

<Image align="center" className="border" border={true} src="https://files.readme.io/424b665-Screenshot_2018-05-16_11.49.03.png" />