> ## Documentation Index
> Fetch the complete documentation index at: https://docs.abbyy.com/llms.txt
> Use this file to discover all available pages before exploring further.

# Working with files

> Exchange files with the ABBYY FlexiCapture Application Server using POST requests: load, save, append, and checksum images, attachments, and XML data.

To exchange files with the Application Server, use a POST request.

Before you send file requests, connect to the Web Services API. For more information, see [Connecting to the Web Services API](/flexi-capture/api/using/connecting).

## Types of actions

Use POST requests to perform the following actions:

| Action value | Description                                                                                   |
| ------------ | --------------------------------------------------------------------------------------------- |
| `Load`       | Load files from the server.                                                                   |
| `Save`       | Save files on the server.                                                                     |
| `Append`     | Append data to the end of a file.                                                             |
| `Checksum`   | Get a checksum for a file from the server. The checksum is calculated using the CRC32 method. |

## Common use cases

* Import images. Load image files, including in parts, and get their checksum.
* Get original page images at any point during processing.
* Work with attachments of batches, documents, and pages (upload and download).
* Get the XML description of a verification task, modify the document, and save the changes on the server.

<Info>
  For large attachments, use POST requests. Large files are divided into smaller parts and uploaded to the server. When you use a POST request to add an attachment to an object, call the [SaveAttachment](/flexi-capture/api/methods/save-attachment) method after the POST request, passing a zero-length file with the name of the transferred file as the `file` parameter. In other cases, use the [Attachments](/flexi-capture/api/methods/attachments) methods developed specifically for attachments.
</Info>

## Request parameters

<Note>
  Make sure that the request fields are completed correctly.
</Note>

| Name         | Type   | Description                                                                                                   |
| ------------ | ------ | ------------------------------------------------------------------------------------------------------------- |
| `Action`     | string | Type of action. For more information, see [Types of actions](#types-of-actions).                              |
| `sessionId`  | int    | Session ID, used to check the user's permissions.                                                             |
| `projectId`  | int    | Project ID.                                                                                                   |
| `batchId`    | int    | Batch ID.                                                                                                     |
| `objectType` | int    | Type of object on the server. For more information, see [Object types](#object-types).                        |
| `objectId`   | int    | Object ID (of a document, page, or task).                                                                     |
| `parentId`   | int    | ID of the parent document. Specify this for document sets; for documents that are not part of a set, use `0`. |
| `version`    | int    | File version.                                                                                                 |
| `streamName` | string | Name of the encoded binary stream. For more information, see [Stream names](#stream-names).                   |
| `blob`       | —      | Binary file data (when `Action` is `Save` or `Append`).                                                       |
| `offset`     | int    | Offset from the start of the file after which to append the data (when `Action` is `Append`).                 |

### Object types

The `objectType` parameter accepts the following values:

| Value | Object type                                                         |
| ----- | ------------------------------------------------------------------- |
| `0`   | Document                                                            |
| `1`   | Page                                                                |
| `5`   | Small copy of the page displayed as a thumbnail (PNG file)          |
| `8`   | Task attachment (XML document)                                      |
| `13`  | File accessible to all users, such as an End-User License Agreement |

<Info>
  Object type `8` (task attachment) is most effective for large attachments. In other cases, use the [Attachments](/flexi-capture/api/methods/attachments) methods developed specifically for attachments.
</Info>

<Note>
  For files of object type `13`, set `projectId` to `0` and `batchId` to `0` — these files do not belong to any project, batch, or tenant. To write a file of this type, the administrator must open a session. To read a file of this type, pass `sessionId=0`; there is no need to open a session.
</Note>

### Stream names

The `streamName` parameter is the name of the binary stream. Use Base64 encoding when saving a file to the server, and UrlEncode encoding when loading a file from the server. The available values depend on the object type.

#### Page stream names

| Value             | Description                                       |
| ----------------- | ------------------------------------------------- |
| `BlackWhiteImage` | The black-and-white image of the page (PNG file). |
| `ColorImage`      | The color image of the page (JPG file).           |
| `Preview`         | Page preview image (PNG file).                    |

#### Document stream names

| Value             | Description                                                                                                                                                                                                                                                                             |
| ----------------- | --------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| `DocumentBody`    | An XML document that describes document fields. Created when preparing the task for the Web stations. After verification, the changes in the document are processed. Versions are not supported; set the `version` parameter to `0`. Save the document processing results to this file. |
| `Page` `pageID`   | `pageID` is the ID of a page returned by the [AddNewPage](/flexi-capture/api/methods/add-new-page) method. Use this stream name to upload a source page image before preprocessing.                                                                                                     |
| `FileName`        | `FileName` is the name of a file specified when creating the document with the [AddNewDocument](/flexi-capture/api/methods/add-new-document) method. Use this stream name to upload a multi-page file with document page images.                                                        |
| `RecognizedWords` | An XML document that contains recognized words and their coordinates on the page.                                                                                                                                                                                                       |

#### Task stream names

* `Verification` — An XML document that describes a verification task. Created when preparing the task for the Web stations. After verification, the changes in the document are processed. Versions are not supported; set the `version` parameter to `1`. Save the task processing results to this file.
* `VerificationRequest` — Corresponds to one of the following requests:
  * An XML document that contains a request to execute operations within a batch, including document separation and page rearrangement. This type of request is used by the Web Station for rule checks.
  * An XML document containing a routing request.
  * An XML document containing a `LineItems` extrapolation request.
  * An XML document containing a data verification request.

## File storage

File Storage contains all files of the project. The file name encodes the object type, object identifier, and stream name in the form `<object type>-<object id>-<stream name>version`.

Page files (`objectType = 1`) contain copies of images, while document files (`objectType = 0`) contain source images. For this reason, you cannot change an image using a POST request with `objectType = 1`.

## Example requests

### Load a file from the server

To load a page file (`objectType = 1`) with `id=4`, `streamName=C:\Temp\image.pdf`, and `version=184201843` from the server, use the following POST request:

```text theme={null}
1-4-C:\Temp\image.pdf184201843
```

### Save a file on the server

To save a document (`objectType = 0`) with `id=4`, `projectId=3`, `batchId=6`, `version=522`, and `streamName=C:\Temp\image.pdf` on the server, use the following POST request:

```csharp theme={null}
resp = FileRequest(
    action: "Save",
    objectType: 0,
    projectId: 3,
    batchId: 6,
    objectId: 4,
    version: 522,
    streamName: "C:\Temp\image.pdf",
    file: new ByteArrayContent(buffer, 0, readed),
    clientCredentials: clientCredentials,
    endpointAddress: endpointAddress);
```

For more information, see [Examples](/flexi-capture/api/files/examples-api-files).
