---
title: "Slack file object"
summary: "Defines an object containing Slack file information to be used in an image block or image element."
url: "https://docs.slack.dev/reference/block-kit/composition-objects/slack-file-object"
type: "reference"
subtype: "block-kit"
---

Source: https://docs.slack.dev/reference/block-kit/composition-objects/slack-file-object

# Slack file object

**Defines an object containing Slack file information to be used in an image block or image element.**

This [file](https://docs.slack.dev/reference/objects/file-object.md) must be an image and you must provide either the URL or ID. In addition, the user posting these blocks must have access to this file. If both are provided then the payload will be rejected. Currently only `png`, `jpg`, `jpeg`, and `gif` Slack image files are supported.

#### Fields {#fields}

Field

Type

Description

Required?

`url`

string

This URL can be the `url_private` or the `permalink` of the Slack file.

Optional

`id`

string

Slack ID of the file.

Optional

#### Example {#example}

The Slack file object must be used within the [image](https://docs.slack.dev/reference/block-kit/blocks/image-block.md) block.

*   JSON
*   Python Slack SDK
*   Node Slack SDK
*   Java Slack SDK

```
{    "blocks": [        {            "type": "image",            "title": {                "type": "plain_text",                "text": "Please enjoy this photo of a kitten"            },            "block_id": "image4",            "slack_file": {                "url": "https://files.slack.com/files-pri/T0123456-F0123456/xyz.png"            },            "alt_text": "An incredibly cute kitten."        }    ]}
```

```python
def example01() -> ImageBlock:
    """
    Defines an object containing Slack file information to be used in an image block or image element.
    https://docs.slack.dev/reference/block-kit/composition-objects/slack-file-object/

    An image block using slack_file with a url.
    """
    block = ImageBlock(
        title=PlainTextObject(text="Please enjoy this photo of a kitten"),
        block_id="image4",
        slack_file=SlackFile(
            url="https://files.slack.com/files-pri/T0123456-F0123456/xyz.png"
        ),
        alt_text="An incredibly cute kitten.",
    )
    return block
```

```javascript
export function example01() {
  /**
   * @type {import('@slack/types').ImageBlock}
   */
  const block = {
    type: "image",
    title: {
      type: "plain_text",
      text: "Please enjoy this photo of a kitten",
    },
    block_id: "image4",
    slack_file: {
      url: "https://files.slack.com/files-pri/T0123456-F0123456/xyz.png",
    },
    alt_text: "An incredibly cute kitten.",
  };
  return block;
}
```

```java
public static ImageBlock example01() {
    ImageBlock block = Blocks.image(i -> i.title(BlockCompositions.plainText("Please enjoy this photo of a kitten"))
            .blockId("image4")
            .slackFile(SlackFileObject.builder()
                    .url("https://files.slack.com/files-pri/T0123456-F0123456/xyz.png")
                    .build())
            .altText("An incredibly cute kitten."));
    return block;
}
```

*   JSON
*   Python Slack SDK
*   Node Slack SDK
*   Java Slack SDK

```
{    "blocks": [        {            "type": "image",            "title": {                "type": "plain_text",                "text": "Please enjoy this photo of a kitten"            },            "block_id": "image4",            "slack_file": {                "id": "F0123456"            },            "alt_text": "An incredibly cute kitten."        }    ]}
```

```python
def example02() -> ImageBlock:
    """
    An image block using slack_file with an id.
    """
    block = ImageBlock(
        title=PlainTextObject(text="Please enjoy this photo of a kitten"),
        block_id="image4",
        slack_file=SlackFile(id="F0123456"),
        alt_text="An incredibly cute kitten.",
    )
    return block
```

```javascript
export function example02() {
  /**
   * @type {import('@slack/types').ImageBlock}
   */
  const block = {
    type: "image",
    title: {
      type: "plain_text",
      text: "Please enjoy this photo of a kitten",
    },
    block_id: "image4",
    slack_file: {
      id: "F0123456",
    },
    alt_text: "An incredibly cute kitten.",
  };
  return block;
}
```

```java
public static ImageBlock example02() {
    ImageBlock block = Blocks.image(i -> i.title(BlockCompositions.plainText("Please enjoy this photo of a kitten"))
            .blockId("image4")
            .slackFile(SlackFileObject.builder().id("F0123456").build())
            .altText("An incredibly cute kitten."));
    return block;
}
```
