# Slack File Upload Action

Upload files from URLs to a Slack channel.

The Slack File Upload Action downloads files from the specified URLs and uploads them to the specified Slack channel. You can use it to share files output by other actions, such as still images captured from a camera, in Slack.

When you post a file URL as a message with the [Slack Notification Action](https://docs.soracom.io/en/services/flux/slack), a URL that expires can no longer be displayed in Slack after it expires. With the Slack File Upload Action, the file itself is stored in Slack, so you can still view it after the original URL expires.

![Screenshot of the action list in the Create a new action dialog, showing Slack File Upload right after Slack Notification.](https://docs.soracom.io/_astro/slack-file-upload-en-01.CNXXcIdV_KKP1m.webp)

> [!WARNING]
>
> This action is available on the Standard and Enterprise plans. See [Plans](https://docs.soracom.io/en/services/flux/plans) for details.

## Preparing Slack

The Slack File Upload Action uploads files using the bot token of a Slack app. Before configuring the action, complete the following steps in Slack:

1. Create a Slack app.

2. Add the `files:write` scope to **Bot Token Scopes** of the Slack app.

3. Install the Slack app to your workspace.

   Installing the app issues a bot token (a string that starts with `xoxb-`). For details on bot tokens, refer to [Token types](https://api.slack.com/authentication/token-types#bot) in the Slack documentation.

4. Invite the Slack app to the channel that you want to upload files to.

5. Check the channel ID (for example, `C0123456789`) of the channel.

6. Register the bot token as a credential set of the **API Token credentials** type, entering the bot token as the API token. For details, refer to [Creating a Credential Set](https://docs.soracom.io/en/services/authentication/credential-sets#creating-a-credential-set).

## Configuration

In the **Action Condition** section, you can specify the conditions under which the action will be executed using the values (Message or Context) from the event source to the channel. For more details on the expressions you can input, refer to [Use Expressions in Actions](https://docs.soracom.io/en/services/flux/action-expressions).

### Configuring Slack File Upload Action

The **Channel ID**, **File URL**, **File title**, **Message**, and **Thread timestamp** fields support [expressions](https://docs.soracom.io/en/services/flux/action-expressions), such as `${payload.imageUrl}`.

![Screenshot of the Slack File Upload Action configuration, showing the Credentials, Channel ID, Files, and Message fields and Advanced settings.](https://docs.soracom.io/_astro/slack-file-upload-en-02.CniTUR0H_w7uYQ.webp)

- **Credentials** (required): Select the credential set that contains the bot token of your Slack app. For details, refer to [Preparing Slack](https://docs.soracom.io/en/services/flux/slack-file-upload/#preparing-slack).

- **Channel ID** (required): Enter the ID of the Slack channel to upload the files to (for example, `C0123456789`).

- **Files**: Enter the URL of each file to upload and an optional title to show in Slack. Add rows to upload up to 10 files.

  - **File URL** (required): Enter the URL of the file.
  - **File title**: Enter the title to show in Slack. If omitted, the file name of the downloaded file is used.
  - To specify multiple files with a single expression (for example, `${payload.files}`), click **Use expression for multiple values (Advanced)**. For details, refer to [Specifying Multiple Files with a Single Expression](https://docs.soracom.io/en/services/flux/slack-file-upload/#specifying-multiple-files-with-a-single-expression).

- **Message**: Enter the message to post with the files.

- **Advanced settings** > **Thread timestamp**: To upload the files as a reply in a thread, enter the timestamp (`thread_ts`) of the parent message (for example, `1234567890.123456`). If omitted, the files are posted to the channel.

### Output

Configure how to handle the output data of the action. Refer to [Enable Republishing of Action Output](https://docs.soracom.io/en/services/flux/action-output#enable-republishing-of-action-output) for more details.

## File Requirements

- You can upload up to 10 files per run.
- Each file can be up to 50 MiB, and the total size of the files in a run can be up to 100 MiB.
- Downloading and uploading each file are each limited to 60 seconds. The entire run is limited to about 4 minutes and 40 seconds.
- Soracom Flux accesses the file URLs without credentials. Specify URLs that can be downloaded from the internet without authentication, such as public URLs or signed URLs. Internal destinations, such as private IP addresses, are not allowed.

If a limit is exceeded or a file cannot be downloaded, the action returns an error.

> [!WARNING]
>
> If you specify a URL that expires, make sure that the action runs before the URL expires.

## File Examples

### Uploading an Image from a Previous Action

Add the Slack File Upload Action to the channel that receives the output of an action that outputs an image URL in `imageUrl`, and configure the action as follows:

- **File URL**: `${payload.imageUrl}`
- **File title**: `${payload.deviceId}`
- **Message**: `Captured a still image from ${payload.deviceId}.`

### Specifying Multiple Files with a Single Expression

Click **Use expression for multiple values (Advanced)** to specify multiple files with a single expression. The expression must evaluate to one of the following formats:

![Screenshot of the Files field in advanced expression mode, with an expression entered in File List.](https://docs.soracom.io/_astro/slack-file-upload-en-03.VlbYTi9Q_Z1Ualgp.webp)

- An array of URLs:

  ```json
  [
    "https://example.com/image1.jpg",
    "https://example.com/image2.png"
  ]
  ```

- An array of objects with `url` (the file URL) and `title` (the file title, optional):

  ```json
  [
    { "url": "https://example.com/image1.jpg", "title": "Entrance camera" },
    { "url": "https://example.com/image2.png", "title": "Warehouse camera" }
  ]
  ```

For example, if `payload.files` contains an array in one of the formats above, specify `${payload.files}` to upload all the files in the array. To use the output of the [Collect Messages Action](https://docs.soracom.io/en/services/flux/collect-messages), extract the file URL from each message in `messages` and convert them into an array in one of the formats above.

> [!NOTE]
>
> - Elements that cannot be interpreted as a URL, such as objects without `url`, are ignored, and the remaining files are uploaded.
> - The limit of 10 files per run also applies when you use an expression.

## Output Data of the Action

When the files are uploaded, the action outputs information about the uploaded files. `files` contains the file information returned by Slack's [files.completeUploadExternal](https://docs.slack.dev/reference/methods/files.completeUploadExternal) method.

Example:

```json
{
  "ok": true,
  "files": [
    {
      "id": "F0123456789",
      "title": "7CDDE9AAAAAA"
    }
  ]
}
```

If the upload fails, the action outputs an error. If the Slack API returns an error, the error message includes the Slack error code (for example, `not_in_channel`, `missing_scope`, or `invalid_auth`). The following table lists common error codes and how to resolve them:

| Error code | Resolution |
| - | - |
| `invalid_auth`, `token_revoked`, `token_expired` | Check the bot token registered in the credential set. |
| `missing_scope` | Add the `files:write` scope to **Bot Token Scopes** of your Slack app, and reinstall the app to your workspace. |
| `not_in_channel`, `channel_not_found` | Check the channel ID, and invite the Slack app to the channel. |
| `ratelimited` | The Slack API rate limit was exceeded. Reduce how often the action runs or the number of files uploaded per run. |

> [!WARNING]
>
> If posting to the channel fails after the files have been transferred to Slack, the transferred files remain private in Slack. Soracom Flux does not delete these files.
