# Harvest Files Event Source

Trigger Flux app actions when files arrive in Soracom Harvest Files.

When you select **Soracom Harvest Files** as the [Event Source](https://docs.soracom.io/en/services/flux/channels-and-event-sources#create-a-channel-and-select-an-event-source) for the Flux App, the App will be triggered when a file is uploaded (created, updated) or deleted in Soracom Harvest Files.

> [!WARNING]
>
> You can create up to 10 Soracom Harvest Files event sources per Soracom Account.

## Event Source Configuration

Configure the conditions under which event messages are published to the channel from the event source.

- **Enabled**: The event source is enabled and can publish event messages to the channel.

- **File Path (Prefix Match)**: Enter the file path in Harvest Files. Files with paths that match this prefix will trigger the event.

- **Event Type**: Event messages are sent when the selected event is detected. You can select multiple events.

  - **File Created**: A file has been newly uploaded.
  - **File Updated**: A file with the same name as an existing file has been uploaded.
  - **File Deleted**: A file has been deleted.

## Data Format

The data sent to a channel configured with the Soracom Harvest Files event source consists of **Message** and **Context**.

> [!WARNING]
>
> You can check the data received by the event to the Flux App in the **History** tab of Soracom Flux Studio. For more details, refer to [View Logs](https://docs.soracom.io/en/services/flux/logs).

### Message

For this event source, the message is the event that occurred in Harvest Files and the path of the file that triggered the event. Here's an example:

```json
{
  "eventType": "updated",
  "path": "/harvest-files-path/filename",
  "contentType": "image/jpeg",
  "presignedUrls": {
    "get": "https://harvest-files.s3.ap-northeast-1.amazonaws.com/xxx"
  }
}
```

| Attribute | Description |
| - | - |
| `eventType` | The type of event that occurred. Either of `created`, `updated`, or `deleted`. |
| `path` | The file path, including the file name. |
| `contentType` | The content type of the file. |
| `presignedUrls.get` | The URL to retrieve the created or updated file. This is not included when the `eventType` is `deleted`. |

> [!NOTE]
>
> The URL of `presignedUrls.get` is only valid for 1 hour from the time of the event.

> [!WARNING]
>
> To reference the event source's **Message** in an action, input it as `${event.payload.<MESSAGE_ATTRIBUTE>}` or `event.payload.<MESSAGE_ATTRIBUTE> == 1`.

### Context

This contains the information about the Harvest Files event source configuration. Here's an example:

```json
{
  "eventType": "harvest_files",
  "configurationId": "01J1CH2MJRVxxxxxxxxxxxxxxx"
}
```

The attributes are as follows:

| Attribute | Description |
| - | - |
| `eventType` | The type of event. When uploading (new, updating) or deleting a file in Soracom Harvest Files triggers the Flux App, the value is `harvest_files`. |
| `configurationId` | An ID unique to each Soracom Harvest Files event source configuration, issued by Harvest Files. |

> [!WARNING]
>
> To reference the above **Context** in an action, input it as `${event.context.<CONTEXT_ATTRIBUTE>}` or `event.context.<CONTEXT_ATTRIBUTE> == 1`.
