> For the complete documentation index, see [llms.txt](https://t1t.gitbook.io/t1c-js-guide/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://t1t.gitbook.io/t1c-js-guide/containers/other/file-exchange.md).

# File Exchange

## Introduction

The File Exchange container allows Trust1Connector to upload or download files from the filesystem to the requesting party. In order to be able to access the file system, a separate `file_exchange` consent is required.

The File Exchange container provides the following functionalities:

* selecting a folder to use (using system folder selection mechanism)
* listing files in selected folder
* downloading a provided file into selected folder
* uploading a file from the selected folder

## Available Functions

The following functions are available in the T1C-JS library:

| JavaScript API |
| -------------- |

| Function     | Input                  | Output                     | Description                                                                                                                            |
| ------------ | ---------------------- | -------------------------- | -------------------------------------------------------------------------------------------------------------------------------------- |
| downloadFile | path, file, fileName   | N/A                        | Creates a file named `fileName` at the `path` location, with file contents `file`                                                      |
| listFiles    | `{ path, extensions }` | list of files in directory | Returns a list of all files in the `path` directory that have an extension included in the `extensions` array                          |
| setFolder    | N/A                    | path of selected directory | Triggers a system file selection dialog that allows the user to select a directory. The selected directory is returned as the response |
| uploadFile   | path                   | fileBuffer                 | Will retrieve the file located at `path` and return it as a fileBuffer                                                                 |

## Detailed Function Overview <a href="#relo-remoteloading-detailedfunctionoverview" id="relo-remoteloading-detailedfunctionoverview"></a>

### downloadFile <a href="#relo-remoteloading-opensession" id="relo-remoteloading-opensession"></a>

Downloads a provided file(Buffer) into the provided directory.

#### Interface <a href="#relo-remoteloading-interface" id="relo-remoteloading-interface"></a>

```javascript
downloadFile(path: string, file: ArrayBuffer, fileName: string)
```

#### Parameters <a href="#relo-remoteloading-parameters" id="relo-remoteloading-parameters"></a>

* **path**: location for the newly created file
* **file**: ArrayBuffer containing binary data to be put in the file
* **fileName**: name to be given to the file

#### Output <a href="#relo-remoteloading-output" id="relo-remoteloading-output"></a>

```javascript
{
    data: string // absolute path of the newly created file
    success: boolean
}
```

### listFiles <a href="#relo-remoteloading-command" id="relo-remoteloading-command"></a>

Returns a list of files in the selected directory.

#### Interface <a href="#relo-remoteloading-interface.1" id="relo-remoteloading-interface.1"></a>

`listFiles({ path: string, extensions: string[] }, callback: (error, data))`

#### Parameters <a href="#relo-remoteloading-parameters.1" id="relo-remoteloading-parameters.1"></a>

* **dataObject** containing two config parameters:
  * **path**:  directory to list
  * **extensions**: array of file extensions to be included in the list

#### Output <a href="#relo-remoteloading-output.1" id="relo-remoteloading-output.1"></a>

```javascript
{
    data: [{
        extension: string,
        last_modification_time: string,
        name: string,
        path: string,
        size: number
    }],
    success: boolean
}
```

### setFolder <a href="#relo-remoteloading-ccid" id="relo-remoteloading-ccid"></a>

Triggers system dialog to select a folder

#### Interface <a href="#relo-remoteloading-interface.2" id="relo-remoteloading-interface.2"></a>

`setFolder(callback?: (error, data))`

#### Parameters <a href="#relo-remoteloading-parameters.2" id="relo-remoteloading-parameters.2"></a>

* none

#### Output <a href="#relo-remoteloading-output.2" id="relo-remoteloading-output.2"></a>

```javascript
{
    data: string // path of the selected folder
    success: boolean
}
```

### uploadFile <a href="#relo-remoteloading-closesession" id="relo-remoteloading-closesession"></a>

Uploads the file located at `path` to the requesting user.

#### Interface <a href="#relo-remoteloading-interface.3" id="relo-remoteloading-interface.3"></a>

`uploadFile(path: string)`

#### Parameters <a href="#relo-remoteloading-parameters.3" id="relo-remoteloading-parameters.3"></a>

* **feature**: absolute path to the requested file

#### Output <a href="#relo-remoteloading-output.3" id="relo-remoteloading-output.3"></a>

```javascript
fileBuffer
```
