> ## Documentation Index
> Fetch the complete documentation index at: https://social-b97141fb-feat-user-history-moderation-detail.mintlify.site/llms.txt
> Use this file to discover all available pages before exploring further.

# Image Posts

> Create image posts with uploaded image files using the current social.plus SDKs.

Image posts combine one or more uploaded images with an optional text caption. Upload the images first, then pass the uploaded image objects or file IDs to the post creation API.

<Info>
  This page focuses on the SDK call that creates the post. See [Image Handling](/social-plus-sdk/core-concepts/content-handling/files-images-and-videos/image-handling) for upload steps, supported file inputs, and upload constraints.
</Info>

<CardGroup cols={2}>
  <Card title="Uploaded Images" icon="images">
    Create posts from image objects or file IDs returned by the file upload flow.
  </Card>

  <Card title="Caption Support" icon="text">
    Add text, metadata, mentions, or other SDK-supported post fields alongside the images.
  </Card>
</CardGroup>

## Parameters

| Parameter | Required | Platforms | Description |
| - | - | - | - |
| `images`, `uploadedImages`, or `fileId` | Yes | TypeScript, iOS, Android, Flutter | Uploaded image objects or image file IDs, depending on SDK. |
| `text` | No | TypeScript, iOS, Android, Flutter | Caption text shown with the image post. |
| `targetType` | Yes | TypeScript, iOS, Android, Flutter | Feed target, usually `community` or `user`. |
| `targetId` | Yes | TypeScript, iOS, Android, Flutter | Community ID or user ID for the target feed. |
| `metadata` | No | TypeScript, iOS, Android, Flutter | Custom metadata stored with the post where supported. |
| `mentionees` | No | TypeScript, iOS, Android, Flutter | User mention payload where supported by the platform builder. |
| `productTags` | No | TypeScript, Android, iOS | Products tagged in the post text. Text product tag types: `Amity.TextProductTag`, `AmityTextProductTag`, `AmityProductTag.Text`. |
| `attachmentProductTags` | No | TypeScript, Android, iOS | Products tagged on individual image attachments. An `AmityAttachmentProductTags` container, keyed by each attachment's `fileId`. |

<Note>
  **Product tags (SDK API).** An image post has a text parent and an image child. `productTags` tags products mentioned in the parent **text**. `attachmentProductTags` tags products on the child **media attachment**, and is not an array: it is an `AmityAttachmentProductTags` container that maps each attachment's `fileId` to that attachment's media tags. Flutter does not expose product tags on any post builder. See [Tag Products](#tag-products) below for both. UIKit's product-tag UI is a separate surface and may support fewer post types; see [UIKit Product Tagging](/uikit/components/social/product-tagging). For tagging limits and tap-through behavior, see [Product Tagging](/uikit/components/social/posts#product-tagging).
</Note>

## Create an Image Post

The examples below create an image post in a community. Replace the target with the SDK's user-feed target when posting to a user.

<CodeGroup>
  ```swift iOS theme={null}
  func createImagePost(
      uploadedImages: [AmityImageData],
      communityId: String
  ) async throws -> AmityPost {
      let postRepository = AmityPostRepository()
      let builder = AmityImagePostBuilder()
      builder.setImages(uploadedImages)
      builder.setText("Photos from today")

      return try await postRepository.createImagePost(
          builder,
          targetId: communityId,
          targetType: .community,
          metadata: nil,
          mentionees: nil
      )
  }
  ```

  ```kotlin Android theme={null}
  fun createImagePost(
      uploadedImages: Set<AmityImage>,
      communityId: String
  ) {
      postRepository.createImagePost(
          targetType = AmityPost.TargetType.COMMUNITY,
          targetId = communityId,
          images = uploadedImages,
          text = "Photos from today"
      )
          .subscribe({ post ->
              showSuccessMessage(post.getPostId())
          }, { error ->
              handleGeneralError(error)
          })
  }
  ```

  ```typescript TypeScript theme={null}
  import { PostRepository } from "@amityco/ts-sdk";

  const { data: post } = await PostRepository.createPost({
    targetType: "community",
    targetId: communityId,
    data: {
      text: "Photos from today",
    },
    attachments: [
      {
        type: "image",
        fileId,
      },
    ],
  });
  ```

  ```dart Flutter theme={null}
  Future<AmityPost> createImagePost(List<AmityImage> uploadedImages) {
    return AmitySocialClient.newPostRepository()
        .createPost()
        .targetCommunity(communityId)
        .image(uploadedImages)
        .text('Photos from today')
        .post();
  }
  ```
</CodeGroup>

## Tag Products

TypeScript, Android, and iOS accept two separate product inputs when creating an image post. The text tag is applied to the parent; the attachment tag is applied to the image child.

| Input | Tags what | Shape |
| - | - | - |
| `productTags` | Products named in the post text | An array of text product tags, each with a character range |
| `attachmentProductTags` | Products shown in one image | An `AmityAttachmentProductTags` container, keyed by `fileId` |

Build `attachmentProductTags` by setting the tags for each uploaded image's `fileId`. Images you do not set tags for stay untagged.

<CodeGroup>
  ```swift iOS theme={null}
  let postRepository = AmityPostRepository()
  let builder = AmityImagePostBuilder()
  builder.setImages(uploadedImages)
  builder.setText("Wearing the featured product today")

  let attachmentTags = AmityAttachmentProductTags()
  attachmentTags.set(
      fileId: uploadedImages[0].fileId,
      tags: [AmityMediaProductTag(productId: "prod_001")]
  )

  let post = try await postRepository.createImagePost(
      builder,
      targetId: communityId,
      targetType: .community,
      metadata: nil,
      mentionees: nil,
      productTags: [
          AmityTextProductTag(productId: "prod_001", index: 12, length: 12)
      ],
      attachmentProductTags: attachmentTags
  )
  ```

  ```kotlin Android theme={null}
  val attachmentTags = AmityAttachmentProductTags.Builder()
  attachmentTags.set(
      uploadedImages.first().getFileId(),
      listOf(AmityProductTag.Media(productId = "prod_001"))
  )

  postRepository.createImagePost(
      targetType = AmityPost.TargetType.COMMUNITY,
      targetId = communityId,
      images = uploadedImages,
      text = "Wearing the featured product today",
      productTags = listOf(
          AmityProductTag.Text(
              productId = "prod_001",
              text = "featured product",
              index = 12,
              length = 16
          )
      ),
      attachmentProductTags = attachmentTags.build()
  )
      .subscribe({ post ->
          showSuccessMessage(post.getPostId())
      }, { error ->
          handleGeneralError(error)
      })
  ```

  ```typescript TypeScript theme={null}
  import { AmityAttachmentProductTags, PostRepository } from "@amityco/ts-sdk";

  const attachmentTags = new AmityAttachmentProductTags();
  attachmentTags.set(fileId, [{ productId: "prod_001" }]);

  const { data: post } = await PostRepository.createPost({
    targetType: "community",
    targetId: communityId,
    data: {
      text: "Wearing the featured product today",
    },
    attachments: [{ type: "image", fileId }],
    productTags: [
      { productId: "prod_001", text: "featured product", index: 12, length: 16 },
    ],
    attachmentProductTags: attachmentTags,
  });
  ```
</CodeGroup>

## Notes

* TypeScript accepts image attachments as `{ type: "image", fileId }`.
* Android accepts a `Set<AmityImage>`.
* iOS accepts `[AmityImageData]`.
* Flutter accepts `List<AmityImage>`.

For mixed attachment types, use [Mixed Media Posts](./mixed-media-post).

## Related Topics

<CardGroup cols={3}>
  <Card title="Image Handling" icon="upload" href="/social-plus-sdk/core-concepts/content-handling/files-images-and-videos/image-handling">
    Upload images before creating image posts.
  </Card>

  <Card title="Mixed Media Posts" icon="layer-group" href="./mixed-media-post">
    Combine images with other supported media attachments.
  </Card>

  <Card title="Posts Overview" icon="newspaper" href="../overview">
    Review post concepts, retrieval, and moderation flows.
  </Card>
</CardGroup>


This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.