> ## Documentation Index
> Fetch the complete documentation index at: https://learn.social.plus/llms.txt
> Use this file to discover all available pages before exploring further.

# File Message

> Send file chat messages with platform-specific file ID, attachment, or URI inputs.

Use file messages for document and generic attachment sharing. TypeScript creates file messages from an uploaded file ID. iOS and Android use `AmityMessageAttachment`. Flutter sends file messages from a `Uri`.

## Parameters

| Parameter                       | Required | Description                                                                          |
| ------------------------------- | -------- | ------------------------------------------------------------------------------------ |
| `subChannelId`                  | Yes      | Target subchannel where the file message will be created.                            |
| `fileId` / `attachment` / `Uri` | Yes      | File input for the message: uploaded file ID, platform attachment, or Flutter `Uri`. |
| `caption`                       | No       | Text caption attached to the file message where the platform exposes it.             |
| `parentId`                      | No       | Parent message ID when sending the file as a reply.                                  |
| `tags`                          | No       | App-defined tags for later filtering or grouping.                                    |
| `metadata`                      | No       | App-defined metadata stored with the message.                                        |

## Send A File Message

Create a file message from an uploaded file ID, native attachment, or Flutter file URI.

<CodeGroup>
  ```typescript TypeScript theme={null}
  import { MessageRepository } from '@amityco/ts-sdk';

  const { data: message } = await MessageRepository.createMessage({
    subChannelId,
    dataType: 'file',
    fileId,
  });

  renderResults(message);
  ```

  ```swift iOS theme={null}
  let fileURL = URL(fileURLWithPath: "/tmp/report.pdf")
  let options = AmityFileMessageCreateOptions(
      subChannelId: "sub-channel-id",
      attachment: .localURL(url: fileURL),
      fileName: "report.pdf",
      caption: "Monthly report"
  )

  let message = try await messageRepository.createFileMessage(options: options)
  showSuccessMessage(message.messageId)
  ```

  ```kotlin Android theme={null}
  val attachment = AmityMessageAttachment.FILE_ID(fileId)

  val disposable = AmityChatClient.newMessageRepository()
      .createFileMessage(
          subChannelId = subChannelId,
          attachment = attachment,
      )
      .caption("Monthly report")
      .build()
      .send()
      .subscribe(
          { showSuccessMessage() },
          { error -> handleGeneralError(error) },
      )
  ```

  ```dart Flutter theme={null}
  final fileUri = Uri.parse('file:///tmp/report.pdf');

  final message = await AmityChatClient.newMessageRepository()
      .createMessage(subChannelId)
      .file(fileUri)
      .caption('Monthly report')
      .send();
  ```
</CodeGroup>

## Replies And Metadata

Add reply context or metadata when the file message belongs to a thread or needs app-owned rendering context.

<CodeGroup>
  ```typescript TypeScript theme={null}
  import { MessageRepository } from '@amityco/ts-sdk';

  const { data: reply } = await MessageRepository.createMessage({
    subChannelId,
    parentId: messageId,
    dataType: 'file',
    fileId,
    tags: ['attachment'],
    metadata: {
      source: 'composer',
    },
  });
  ```

  ```dart Flutter theme={null}
  final fileUri = Uri.parse('file:///tmp/report.pdf');

  final reply = await AmityChatClient.newMessageRepository()
      .createMessage(subChannelId)
      .parentId(messageId)
      .file(fileUri)
      .caption('Adding the report here')
      .metadata({'source': 'composer'})
      .send();
  ```
</CodeGroup>

## Related Topics

<CardGroup cols={2}>
  <Card title="Image Message" href="./image-message" icon="image">
    Send image attachments.
  </Card>

  <Card title="Audio Message" href="./audio-message" icon="mic">
    Send audio attachments where supported.
  </Card>
</CardGroup>
