> ## 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.

# Image Comment

> Create comments with uploaded image attachments.

Image comments are comments with image attachment file IDs. Upload each image first, then pass the uploaded file ID to the comment creation API. You can also include text with the image attachment.

<Info>
  Comment creation accepts uploaded image file IDs. Use the file or image upload APIs before creating the comment.
</Info>

## Parameters

| Operation               | Parameter              | Required | Description                                            |
| ----------------------- | ---------------------- | -------- | ------------------------------------------------------ |
| Create an image comment | `referenceId`          | Yes      | Target content ID for the comment, such as a post ID.  |
| Create an image comment | `referenceType`        | Yes      | Target content type, such as `post`.                   |
| Create an image comment | Uploaded image file ID | Yes      | File ID returned by the image upload API.              |
| Create an image comment | `text`                 | No       | Optional text body included with the image attachment. |
| Reply with an image     | `parentId`             | Yes      | Parent comment ID when creating an image reply.        |

## Create an Image Comment

Create an image comment from an uploaded image file ID, with optional text where supported.

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

  const { data: comment } = await CommentRepository.createComment({
    referenceId: postId,
    referenceType: "post",
    data: {
      text: "Photo response",
    },
    attachments: [
      {
        type: "image",
        fileId: imageFileId,
      },
    ],
  });

  renderResults(comment);
  ```

  ```swift iOS theme={null}
  let options = AmityCommentCreateOptions(
      referenceId: "post-id",
      referenceType: .post,
      text: "Photo response",
      attachments: [
          .image(fileId: "uploaded-image-id")
      ]
  )

  let comment = try await commentRepository.createComment(with: options)
  showSuccessMessage(comment.commentId)
  ```

  ```kotlin Android theme={null}
  val imageAttachment = AmityComment.Attachment.IMAGE(
      fileId = fileId,
      image = null
  )

  AmitySocialClient.newCommentRepository()
      .createComment()
      .post(postId = postId)
      .with()
      .attachments(imageAttachment)
      .text(text = "Photo response")
      .build()
      .send()
      .subscribe(
          { comment -> showSuccessMessage(comment.getCommentId()) },
          { error -> handleGeneralError(error) }
      )
  ```

  ```dart Flutter theme={null}
  final comment = await AmitySocialClient.newCommentRepository()
      .createComment()
      .post(postId)
      .create()
      .attachments([
        CommentImageAttachment(fileId: fileId),
      ])
      .text('Photo response')
      .send();

  final commentId = comment.commentId;
  ```
</CodeGroup>

## Reply with an Image

Set `parentId` before the platform-specific create step.

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

  const { data: reply } = await CommentRepository.createComment({
    referenceId: postId,
    referenceType: "post",
    parentId: commentId,
    attachments: [
      {
        type: "image",
        fileId: imageFileId,
      },
    ],
  });

  renderResults(reply);
  ```

  ```swift iOS theme={null}
  let options = AmityCommentCreateOptions(
      referenceId: "post-id",
      referenceType: .post,
      text: "",
      attachments: [
          .image(fileId: "uploaded-image-id")
      ],
      parentId: "parent-comment-id"
  )

  let reply = try await commentRepository.createComment(with: options)
  showSuccessMessage(reply.commentId)
  ```

  ```kotlin Android theme={null}
  val imageAttachment = AmityComment.Attachment.IMAGE(
      fileId = fileId,
      image = null
  )

  AmitySocialClient.newCommentRepository()
      .createComment()
      .post(postId = postId)
      .parentId(parentId = commentId)
      .with()
      .attachments(imageAttachment)
      .build()
      .send()
      .subscribe(
          { reply -> showSuccessMessage(reply.getCommentId()) },
          { error -> handleGeneralError(error) }
      )
  ```

  ```dart Flutter theme={null}
  final reply = await AmitySocialClient.newCommentRepository()
      .createComment()
      .post(postId)
      .parentId(commentId)
      .create()
      .attachments([
        CommentImageAttachment(fileId: fileId),
      ])
      .send();

  final replyId = reply.commentId;
  ```
</CodeGroup>

## Notes

* Reuse the uploaded image file ID returned by the upload API; do not pass a local file path to comment creation.
* If your product needs image moderation or file-size limits, apply those rules before upload.
* Query the resulting comment if you need composed file metadata such as rendered image information.

## Related Topics

<CardGroup cols={2}>
  <Card title="Text Comment" icon="message-square" href="./text-comment">
    Create text comments and replies.
  </Card>

  <Card title="Image Handling" icon="upload" href="/social-plus-sdk/core-concepts/content-handling/files-images-and-videos/image-handling">
    Upload image files before attaching them to comments.
  </Card>
</CardGroup>
