> For the complete documentation index, see [llms.txt](https://docs.appmixer.com/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://docs.appmixer.com/connector-configuration/utils/storage/save-to-file.md).

# Save To File

### Overview

The **Save to File Component** exports stored data to a file, allowing structured storage and retrieval of stored records in CSV or JSON format.

### Usage

This component is used to extract data from storage and save it as a downloadable file, providing flexible export options such as sorting and value flattening.

#### Input Ports

| Port | Description                                                                                    |
| ---- | ---------------------------------------------------------------------------------------------- |
| `in` | Receives parameters for file generation, including storage ID, file type, and sorting options. |

#### Output Ports

| Port  | Description                                                             |
| ----- | ----------------------------------------------------------------------- |
| `out` | Emits the file ID of the saved file and the number of records exported. |

#### Properties

| Property       | Type      | Description                                           |
| -------------- | --------- | ----------------------------------------------------- |
| `storeId`      | `string`  | The ID of the storage space to export data from.      |
| `fileName`     | `string`  | The name of the exported file.                        |
| `sortBy`       | `string`  | Sorts records by `key`, `createdAt`, or `updatedAt`.  |
| `fileType`     | `string`  | File format: `csv` or `json`.                         |
| `flattenValue` | `boolean` | If `true`, flattens nested JSON values before saving. |

#### Processing Logic

1. **Retrieves Stored Data**: Extracts data from the specified `storeId`.
2. **Sorts Data**: Orders records based on the selected `sortBy` property.
3. **Formats Output**:
   * If `fileType` is CSV, converts records to CSV format.
   * If `flattenValue` is enabled, nested JSON structures are flattened.
4. **Saves to File**: Exports the processed data and returns a file ID.

#### Output Data Schema

| Property   | Type     | Description                     |
| ---------- | -------- | ------------------------------- |
| `fileId`   | `string` | The ID of the generated file.   |
| `nRecords` | `number` | The number of records exported. |

### Notes

* **Flexible Export Options**: Supports JSON and CSV formats.
* **Sorting Capabilities**: Allows sorting by key or timestamps.
* **Flattening Support**: Enables structured flattening of nested values.

This component is ideal for workflows requiring data extraction, structured storage, and external file exports for further analysis or backup.


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## Querying This Documentation
If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter, and the optional `goal` query parameter:

```
GET https://docs.appmixer.com/connector-configuration/utils/storage/save-to-file.md?ask=<question>&goal=<endgoal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is optional and describes the broader end goal you are ultimately trying to accomplish on behalf of the user. GitBook uses it to tailor the answer towards what is most useful for that goal.

The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
