Based on the [Slack Developer Docs](https://docs.slack.dev/messaging/working-with-files), here is a structured summary of working with files in Slack. ### **Overview** Slack treats files as [messages](https://docs.slack.dev/messaging) with additional complex information. There are two distinct ways to handle files: * **[Uploading files](https://docs.slack.dev/messaging/working-with-files#upload):** Slack hosts the file directly. * **[Adding remote files](https://docs.slack.dev/messaging/working-with-files#remote):** You host the file elsewhere and Slack stores a reference pointer. --- ### **1. Uploading Files** This method is recommended for most apps. Slack hosts the file, scans it for malware, and manages storage. #### **App Setup** * **[Scopes](https://docs.slack.dev/messaging/working-with-files#upload_scopes):** * `files:read`: Access to read file info and list files. * `files:write`: Allows uploading and removing files. * **[Events](https://docs.slack.dev/messaging/working-with-files#upload_events):** Subscribe to events like `file_created`, `file_shared`, `file_deleted`, or `file_change` to react to user actions. #### **The Upload Process** Since files can be large, the API uses a three-step process: 1. **Get Upload URL:** Call `[files.getUploadURLExternal](https://docs.slack.dev/messaging/working-with-files#upload-step-1)` to generate a destination URL. 2. **Upload Content:** POST the file's binary content to the `upload_url` received in step 1. 3. **Complete Upload:** Call `[files.completeUploadExternal](https://docs.slack.dev/messaging/working-with-files#upload-step-3)` to finalize the file. * You can specify `channel_id` to share it immediately. * You can add an `initial_comment` to introduce the file. > **Tip:** Slack's [Node, Python, and Java SDKs](https://docs.slack.dev/messaging/working-with-files#sdks) include helper methods (like `uploadV2`) that handle these steps in a single function call. --- ### **2. Adding Remote Files** Remote files act as pointers to external content. This is useful if you need to host files yourself (e.g., for copyright reasons), want custom search indexing, or desire rich custom unfurls. #### **App Setup** * **[Scopes](https://docs.slack.dev/messaging/working-with-files#remote_files_scopes):** Requires specific permissions like `remote_files:read`, `remote_files:write`, and `remote_files:share`. * **Unfurling Scopes:** `links:read` and `links:write` are often needed to detect and unfurl links to your external files. #### **Workflow** * **[Add](https://docs.slack.dev/messaging/working-with-files#adding):** Use `files.remote.add` to register the file with Slack. * **Preview Image:** You can provide a binary `preview_image` for a better visual experience than a raw URL. * **Search:** Use `indexable_file_contents` to upload a text file containing keywords so users can find your file via Slack search. * **[Share](https://docs.slack.dev/messaging/working-with-files#sharing):** Adding a file doesn't automatically post it. You must call `files.remote.share` to make it visible in a channel. * **[Unfurl](https://docs.slack.dev/messaging/working-with-files#unfurling):** To make links to your files look good when users paste them, listen for the `link_shared` event and respond using `chat.unfurl`. * **Manage:** You can also [update](https://docs.slack.dev/messaging/working-with-files#updating) or [remove](https://docs.slack.dev/messaging/working-with-files#removing) remote files via the API. --- ### **Comparison** | Feature | Uploading Files | Remote Files | | :--- | :--- | :--- | | **Hosting** | Hosted by Slack | Hosted by you (External) | | **Complexity** | Simple (Standard API) | Moderate (Requires Add + Share steps) | | **Search** | Slack indexes contents automatically | You provide `indexable_file_contents` | | **Visuals** | Standard Slack previews | Custom `preview_image` & unfurls |