---
title: "Working with files"
summary: "Working with files may seem daunting, but we're here to help! Think of files as messages but with extra information included. Since files can represent information that is quite complex, an app that uses files well can communicate more precisely. In the following sections, we'll explore the two ways of working with files and their distinct differences."
url: "https://docs.slack.dev/messaging/working-with-files"
type: "guide"
---

Source: https://docs.slack.dev/messaging/working-with-files

# Working with files

Working with files may seem daunting, but we're here to help! Think of files as [messages](https://docs.slack.dev/messaging.md) but with extra information included. Since files can represent information that is quite complex, an app that uses files well can communicate more precisely. In the following sections, we'll explore the two ways of working with files and their distinct differences.

[Uploading files](#upload) allows you to:

*   treat files like messages, and
*   upload files directly to and host files within Slack.

[Adding remote files](#remote) allows you to:

*   keep your files hosted wherever you please,
*   reference and unfurl files remotely, and
*   harness the power of the Remote Files API.

## Uploading files {#upload}

When you upload a file to Slack, Slack becomes the host for your file. Uploading files is the easiest way to manage files in Slack.

### App setup {#setup_file_uploads}

In order to upload a file to Slack, there are some [scopes](https://docs.slack.dev/reference/scopes.md) your app should have, as well as some [events](https://docs.slack.dev/reference/events.md) you may want your app to subscribe to.

### Scopes {#upload_scopes}

Within the **Apps** page, select **OAuth & Permissions** to choose your scopes:

*   The [`files:read`](https://docs.slack.dev/reference/scopes/files.read.md) scope allows access to API methods that read files: [`files.info`](https://docs.slack.dev/reference/methods/files.info.md) and [`files.list`](https://docs.slack.dev/reference/methods/files.list.md).
*   The [`files:write`](https://docs.slack.dev/reference/scopes/files.write.md) scope allows your app to upload files. It also allows your app to [remove](https://docs.slack.dev/reference/methods/files.remote.remove.md) files.

### Events {#upload_events}

To subscribe to file events, navigate to the **Event Subscriptions** tab within your **Apps** page. The file events you may subscribe to are as follows:

*   [`file_change`](https://docs.slack.dev/reference/events/file_change.md): A file was changed.
*   [`file_created`](https://docs.slack.dev/reference/events/file_created.md): A file was created.
*   [`file_deleted`](https://docs.slack.dev/reference/events/file_deleted.md): A file was deleted.
*   [`file_public`](https://docs.slack.dev/reference/events/file_public.md): A file was made public.
*   [`file_shared`](https://docs.slack.dev/reference/events/file_shared.md): A file was shared.
*   [`file_unshared`](https://docs.slack.dev/reference/events/file_unshared.md): A file was unshared.

### Steps for uploading files {#uploading_files}

When a user uploads a file, Slack will scan the file for malware before making it available in the workspace. This means the bigger the file, the longer the scan may take. As such, we've broken down the uploading process into the following steps.

### Call the files.getUploadURLExternal API method {#upload-step-1}

The response will contain a URL to which you can then post the contents of your file.

An example request can look like this:

```sh
curl --location 'https://slack.com/api/files.getUploadURLExternal' \
--header 'Authorization: Bearer {token}' \
--form 'filename="hello.txt"' \
--form 'length="12"'
```

Required parameters are as follows:

*   `filename`: the name of the file being uploaded
*   `length`: the size (in bytes) of the file being uploaded

An example response can look like this:

```json
{
    "ok": true,
    "upload_url": "https://files.slack.com/upload/v1/abcdefghi",
    "file_id": "F012AB3CDE4"
}
```

### Post the contents of your file to the URL returned by the files.getUploadURLExternal API method {#upload-step-2}

An example request (using HTTP POST) can look like this:

```sh
curl --location 'https://files.slack.com/upload/v1/abcdefghi' \
--header 'Content-Type: application/octet-stream' \
--data-binary '@postman-cloud:///1f0a8ecf-f6c9-4620-9684-b3b7d0cb0ff0'
```

Check the HTTP status code to verify the file’s successful upload. An example response can look like this:

```json
OK - 12
```

### Call the files.completeUploadExternal API method {#upload-step-3}

An example request can look like this:

```sh
curl --location 'https://slack.com/api/files.completeUploadExternal' \
--header 'Authorization: Bearer {token}' \
--form 'files="[{\"title\":\"Hello file\", \"id\":\"F012AB3CDE4\"}]"' \
--form 'channel_id="C0123AB4CDE"' \
--form 'initial_comment="Hello file"'
```

Required parameters are as follows:

*   `files`: an array of file IDs and their corresponding (optional) titles.
*   For posting the file:
    *   `channel_id`: the channel ID where the file will be shared. If not specified, the file will only be uploaded, i.e., hosted in Slack - the file will therefore be private, as it is not actually shared anywhere.
    *   `channels`: whether the file has to be shared in multiple channels (comma-separated string of channel IDs).
    *   `initial_comment`: the message text introducing the file in a specified channel.

Once your upload succeeds, you'll see an HTTP response from Slack containing an `"ok": true` field, plus a `files` array containing [`file` objects](https://docs.slack.dev/reference/objects/file-object.md). For more detail on file objects and the fields contained inside, refer to the [file object](https://docs.slack.dev/reference/objects/file-object.md) page.

An example response can look like this:

```json
{
    "ok": true,
    "files": [
        {
            "id": "F012AB3CDE4",
            "created": 1760688042,
            "timestamp": 1760688042,
            "name": "hello.txt",
            "title": "Hello file",
            "mimetype": "text/plain",
            "filetype": "text",
            "pretty_type": "Plain Text",
            "user": "U012A3456BC",
            "user_team": "E0123ABCDEF",
            "editable": true,
            "size": 12,
            "mode": "snippet",
            "is_external": false,
            "external_type": "",
            "is_public": true,
            "public_url_shared": false,
            "display_as_bot": false,
            "username": "",
            "url_private": "https://files.slack.com/files-pri/T0123ABCD4E-FF012AB3CDE4/hello.txt",
            "url_private_download": "https://files.slack.com/files-pri/T0123ABCD4E-F012AB3CDE4/download/hello.txt",
            "permalink": "https://aretia.enterprise.dev.slack.com/files/U012R6127MZ/F012AB3CDE4/hello.txt",
            "permalink_public": "https://slack-files.com/T0123ABCD4E-F012AB3CDE4-8627274cfa",
            "edit_link": "https://aretia.enterprise.slack.com/files/U012R6127MZ/F012AB3CDE4/hello.txt/edit",
            "preview": "Hello txt",
            "preview_highlight": "<div class=\"CodeMirror cm-s-default CodeMirrorServer\">\n<div class=\"CodeMirror-code\">\n<div><pre>Hello txt</pre></div>\n</div>\n</div>\n",
            "lines": 1,
            "lines_more": 0,
            "preview_is_truncated": false,
            "comments_count": 0,
            "is_starred": false,
            "shares": {
                "public": {
                    "C0123AB4CDE": [
                        {
                            "reply_users": [],
                            "reply_users_count": 0,
                            "reply_count": 0,
                            "ts": "1760688662.900279",
                            "channel_name": "general",
                            "team_id": "T0123ABCD4E",
                            "share_user_id": "U012A3456BC",
                            "source": "UNKNOWN",
                            "is_silent_share": false
                        }
                    ]
                }
            },
            "channels": [
                "C0123AB4CDE"
            ],
            "groups": [],
            "ims": [],
            "has_more_shares": false,
            "has_rich_preview": false,
            "file_access": "visible"
        }
    ]
}
```

* * *

### Slack SDKs {#sdks}

Life is easier with an [SDK](https://docs.slack.dev/tools.md). In particular, there are helpful `uploadV2` methods available in our Node Python, and Java libraries that wrap the above steps into a single method. You can also use the `Slack file object` to host files in Slack using [Block Kit](https://docs.slack.dev/block-kit.md). Refer to the [Slack file object](https://docs.slack.dev/reference/block-kit/composition-objects/slack-file-object.md) section for more details.

* * *

## Other API methods for working with files {#other_methods}

Slack provides some other API methods for working with files:

*   [`files.delete`](https://docs.slack.dev/reference/methods/files.delete.md): delete a file.
*   [`files.info`](https://docs.slack.dev/reference/methods/files.info.md): get information on a file.
*   [`files.list`](https://docs.slack.dev/reference/methods/files.list.md): list visible files.
*   [`files.revokePublicURL`](https://docs.slack.dev/reference/methods/files.revokepublicurl.md): disable a file for public sharing.
*   [`files.sharedPublicURL`](https://docs.slack.dev/reference/methods/files.sharedpublicurl.md): enable a file for public sharing.

* * *

## Downloading files {#download}

To download a file hosted by Slack, send a `GET` request to the file's `url_private` or `url_private_download` with your token in an `Authorization: Bearer` header. The token needs the [`files:read`](https://docs.slack.dev/reference/scopes/files.read.md) scope.

Not every file in Slack is hosted by Slack. When an app adds a [remote file](#remote), Slack returns the app-supplied `external_url` as `url_private`. That URL can point to any host, and `url_private_download` is usually absent.

Never send Slack credentials to a host outside Slack

Any app with the [`remote_files:write`](https://docs.slack.dev/reference/scopes/remote_files.write.md) scope chooses the URL that appears in a remote file's `url_private`. If your app attaches a token, session cookie, or other Slack credential to that URL, it sends those credentials to the external host.

Before your app attaches credentials to `url_private`, `url_private_download`, or any thumbnail URL:

1.  Check whether the file is a remote file. A remote file has `"mode": "external"`, `"is_external": true`, and `"filetype": "remote"`. Treat its `url_private` as an ordinary external link: request it without Slack credentials, or don't request it at all.
2.  Parse the URL and confirm that the scheme is `https` and that the host exactly matches a Slack file host your app expects, such as `files.slack.com`. Compare the parsed host, not a prefix or substring of the URL string, so that hosts like `files.slack.com.example.com` don't pass.
3.  Handle redirects deliberately. Either turn off automatic redirects, or check each redirect target with the same rule and drop the `Authorization` header and cookies for any target that fails it. Many HTTP clients forward headers to subdomains or same-host redirects by default.

* * *

## Responding to files {#responding_to_files}

Slack also sends [events](https://docs.slack.dev/apis/events-api.md) when files are uploaded or changed in your workspace. Here are some of the relevant events:

*   [`file_change`](https://docs.slack.dev/reference/events/file_change.md): A file was changed.
*   [`file_created`](https://docs.slack.dev/reference/events/file_created.md): A file was created.
*   [`file_deleted`](https://docs.slack.dev/reference/events/file_deleted.md): A file was deleted.
*   [`file_public`](https://docs.slack.dev/reference/events/file_public.md): A file was made public.
*   [`file_shared`](https://docs.slack.dev/reference/events/file_shared.md): A file was shared.
*   [`file_unshared`](https://docs.slack.dev/reference/events/file_unshared.md): A file was unshared.

* * *

## Adding remote files {#remote}

Remote files are files _not_ hosted inside Slack. Think of a remote file as a pointer, a forwarding address, or a reference to a file that lives elsewhere.

**For most apps, uploading files directly to Slack is preferred over adding remote files**. Adding remote files involves extra steps that may not be necessary for your use case.

### Why use remote files? {#why}

There are a few benefits to adding and sharing remote files to Slack:

*   If your file can't be hosted in Slack for property rights reasons, remote files are here to save the day.
*   If you wish to provide a rich, custom unfurl experience for your files when their links are shared, remote files bring forth fantastical unfurls for the low low price of a JSON object.
*   If you want to control the way your file appears in Slack searches so that others can find it later, remote files allow for customized `indexable content`. That way, you can ensure your file appears when users search for certain terms.

Terminology

Remote files are "added" to Slack, not "uploaded." Adding a remote file to Slack makes Slack aware of its existence. Once that's done, "sharing" a remote file, like sharing a direct upload file, brings the file into a conversation. So a remote file must be "added" before it is "shared".

You can [add](https://docs.slack.dev/reference/methods/files.remote.add.md), [update](https://docs.slack.dev/reference/methods/files.remote.update.md), [remove](https://docs.slack.dev/reference/methods/files.remote.remove.md), [share](https://docs.slack.dev/reference/methods/files.remote.share.md), and [unfurl](https://docs.slack.dev/reference/methods/chat.unfurl.md) remote files in Slack.

### App setup {#setup_remote_files}

In order to add a remote file to Slack, there are a couple of scopes your app should have. There are also some events you may want your app to subscribe to.

### Scopes {#remote_files_scopes}

Working with remote files requires a distinct set of scopes from those involved in direct upload. Again, under the **Apps** page of your app, choose the **OAuth & Permissions** sidebar to select scopes.

*   [`remote_files:read`](https://docs.slack.dev/reference/scopes/remote_files.read.md) allows your app to read information about remote files visible to the user associated with your user token.
*   [`remote_files:share`](https://docs.slack.dev/reference/scopes/remote_files.share.md) allows your app to share remote files visible to the user associated with your user token.
*   [`remote_files:write`](https://docs.slack.dev/reference/scopes/remote_files.write.md) allows your app to add, edit, or delete remote files on a user's behalf.
*   [`chat:write`](https://docs.slack.dev/reference/scopes/chat.write.md) allows your app to post messages in approved channels & conversations. This is especially useful for an app that provides a custom unfurl for remote files.
*   [`links:read`](https://docs.slack.dev/reference/scopes/links.read.md) allows your app to view and subscribe to events about links that have been shared in conversation. Again, this is useful for knowing when a link to your remote file has been shared, so that you can unfurl it.
*   [`links:write`](https://docs.slack.dev/reference/scopes/links.write.md) allows your app to unfurl links (like to remote files) using the [`chat.unfurl`](https://docs.slack.dev/reference/methods/chat.unfurl.md) API method.

Once you've obtained the necessary scopes, you can [add](https://docs.slack.dev/reference/methods/files.remote.add.md), [update](https://docs.slack.dev/reference/methods/files.remote.update.md), [remove](https://docs.slack.dev/reference/methods/files.remote.remove.md), [share](https://docs.slack.dev/reference/methods/files.remote.share.md), and [unfurl](https://docs.slack.dev/reference/methods/chat.unfurl.md) remote files in Slack.

### Events {#remote_files_events}

To subscribe to any file events, use the **Event Subscriptions** tab under your **Apps** page. One event that can be especially useful to apps that work with remote files is the [`link_shared`](https://docs.slack.dev/reference/events/link_shared.md) event, which notifies your app when a link has been shared so that you can unfurl it. Add any App Unfurl Domains that relate to your file service under that same tab in the **Apps** page.

Once you've obtained the necessary scopes and subscribed to any desired events, you can [add](https://docs.slack.dev/reference/methods/files.remote.add.md), [update](https://docs.slack.dev/reference/methods/files.remote.update.md), [remove](https://docs.slack.dev/reference/methods/files.remote.remove.md), [share](https://docs.slack.dev/reference/methods/files.remote.share.md), and [unfurl](https://docs.slack.dev/reference/methods/chat.unfurl.md) remote files in Slack.

### Steps for adding remote files {#adding}

To add a remote file, use the [`files.remote.add`](https://docs.slack.dev/reference/methods/files.remote.add.md) API method.

Remote files exist across the whole workspace (or organization, for Enterprise organizations).

Here's a sample call:

```sh
curl -F token=<token> \
    -F external_id=ABCD1 \
    -F external_url=https://mydocuments.com/document/d/1TA9fIaph4eSz2fC_1JGMuYaYUc4IvieIop0WqfCXw5Y/edit?usp=sharing \
    -F title=LeadvilleAndBackAgain \
    -F preview_image=@cycling.jpg  \
    -F indexable_file_contents=search_terms.txt
    https://slack.com/api/files.remote.add
```

Pay particular attention to the `preview_image` parameter. `preview_image` should be a binary image file, and it will be stored in Slack. That's going to allow a more beautiful unfurl in the next step, when the app actually shares the remote file.

`indexable_file_contents` also deserves a mention. Use this parameter to specify a file containing the search terms that correspond to this remote file. When a user searches in Slack, their query will be compared against the contents of this text file for matching.

Think of this text file like the `alt` parameter on an HTML `<img>` tag — a textual representation of a non-textual object. The text file can contain a description of the remote file, or it can contain search keywords, or anything else text-based.

Once your upload succeeds, you'll see an HTTP response from Slack containing an `"ok": true` field, plus a [`file` object](https://docs.slack.dev/reference/objects/file-object.md). For more detail on file objects and the fields contained inside, a look at the [file object documentation](https://docs.slack.dev/reference/objects/file-object.md) is highly recommended.

You'll see the `external_id` returned to you on the `file` object in the Slack response, as well as a `file_id`. Either of these ids can be stored and used to query the [`files.remote.info`](https://docs.slack.dev/reference/methods/files.remote.info.md) API method to access other information about the file.

The `url_private` field of the returned `file` object contains your `external_url`, not a Slack URL. Apps that read remote files from Slack, such as through events or the [`files.info`](https://docs.slack.dev/reference/methods/files.info.md) API method, receive the same external URL, so they must not send Slack tokens to it. For the checks to run before downloading any file, refer to [Downloading files](#download).

### Sharing remote files {#sharing}

Adding is nice, but sharing is caring.

In other words, adding a remote file _does not_, by itself, share the file to a conversation. Without sharing the file, it remains an orphan inside Slack - you can view information on it via [`files.remote.info`](https://docs.slack.dev/reference/methods/files.remote.info.md) API method, but it won't actually be visible anywhere. Let's make it visible with a call to the [`files.remote.share`](https://docs.slack.dev/reference/methods/files.remote.share.md) API method.

```sh
curl -F token=<token> \
    -F external_id=ABCD1 \
    -F channels=C12345 \
    https://slack.com/api/files.remote.share
```

Now we get a lovely message in channel that shows off the remote file as it should be seen.

Now we have a custom `preview_image`, which we specified during the [`add`](#adding) step, instead of the ugly raw URL and a small picture of text.

A word about tokens: the [`files.remote.share`](https://docs.slack.dev/reference/methods/files.remote.share.md) API method may be called with _either_ a [bot](https://docs.slack.dev/authentication/tokens.md#bot) or a [user](https://docs.slack.dev/authentication/tokens.md#user) token. The bot token shares the file from your app, while the user token shares the file from the user associated with your user token. Use the bot token to share to channels that the bot has access to; use the user token to share to channels that the user has access to.

### Unfurling remote files {#unfurling}

We've already mentioned how to [add a custom `preview_image`](#adding) that makes our remote files appear nicer when they're shared. But what about when someone else shares our remote file as a link?

There are a few ways to do this. First, you can provide a rich, interactive unfurl experience by implementing [Work Objects](https://docs.slack.dev/messaging/work-objects-overview.md) within your app.

You can also provide unfurls with the [`link_shared`](https://docs.slack.dev/reference/events/link_shared.md) event. When the `link_shared` event fires, you'll receive its payload, including the `message_ts` of the message that triggered it, as well as the `channel` of that message. Then you can make an HTTP request to the [chat.unfurl](https://docs.slack.dev/reference/methods/chat.unfurl.md) API method. To do this, set up the `unfurls` object using a [block](https://docs.slack.dev/messaging.md#complex_layouts):

```sh
unfurls: {
        'https://mydocuments.com/document/d/1TA9fIaph4eSz2fC_1JGMuYaYUc4IvieIop0WqfCXw5Y/edit?usp=sharing': {
          hide_color: true,
          blocks: [{
            type: 'file',
            external_id: 'ABCD1',
            source: 'remote',
          }]
        }
      }
```

For use specifically with a file unfurl, you can set the `hide_color` field to `true` to remove the color bar from a message. This property works only with a file block; if this property is included along with other blocks (for example, a section block), the [`chat.unfurl`](https://docs.slack.dev/reference/methods/chat.unfurl.md) API method will throw an error. Then, call the [`chat.unfurl`](https://docs.slack.dev/reference/methods/chat.unfurl.md) API method with the `channel` from the `link_shared` event, and set the `ts` equal to the `message_ts` from the event:

```sh
curl -F token=<user_token> \
    -F ts=123456789.9875 \
    -F unfurls=<unfurls json from above> \
    -F channel=C12345 \
    -F user_auth_required=false \
    https://slack.com/api/chat.unfurl
```

### Updating remote files {#updating}

Your remote file's contents may change. When that happens, call the [`files.remote.update`](https://docs.slack.dev/reference/methods/files.remote.update.md) API method to update your remote file:

```sh
curl -F token=<token> \
    -F tile=ACyclistTale \
    -F external_id=ABCD1 \
    https://slack.com/api/files.remote.update
```

You _cannot_ update the `external_id` or `file_id` of a remote file. If you need to change those fields, your best bet is to [remove](#removing) and then [add](#adding) the file.

One other piece of pleasant news: [adding](#adding) a remote file is actually an "upsert" operation, meaning that if you add a file that has been added before, the existing file will be updated.

### Removing remote files {#removing}

Removing a remote file follows the same pattern as [adding](#adding) and [updating](#updating). Use the [`files.remote.remove`](https://docs.slack.dev/reference/methods/files.remote.remove.md) API method to remove a remote file from Slack.

This API method does _not_ delete the remote file from where it's externally hosted; it only removes the remote file from Slack.

```sh
    curl -F token=<bot_token> \
    -F external_id=ABCD1 \
    https://slack.com/api/files.remote.remove
```

After removal, any place that used to display the file will show a tombstone message containing the text "This file was deleted." instead.
