Image Message

Amity will automatically optimize the image and when queried, will return the image in small, medium and large sizes. If the image is marked as isFull on upload, the original size of the image can also be returned.

Requirements for Images

  • Supported image types are JPG and PNG.

  • The maximum file size of the image is 1 GB.

When an image is uploaded, it is automatically resized into multiple sizing options. The size of the image is determined by its longest dimension (in pixels) with the aspect ratios being unchanged.

Sending a message with image

To create an image message, you need to leverage the FileRepository. Create an image and pass the image ID into the createImageMessage later on. This method also accepts an optional caption parameter to be able to display additional text with the message. You can add up to 1,000 characters of text caption per message.

Here's a small example on how to create a message with an image attached. The process is pretty simple:

  1. Upload an image.

  2. Create a message with the uploaded image ID.

import { FileRepository, MessageRepository } from '@amityco/js-sdk';

// this function takes in input a File from a <input type="file" />
const createImageMessage = (file: File) => {
  // first, create the file object.
  const liveFile = FileRepository.createFile({ file })

  // second, create the message object with the fileId from the liveFile
  const liveMessage = MessageRepository.createImageMessage({
    channelId: 'my-channel',
    imageId: liveFile.model.fileId,
    caption: 'have a look!',
    tags: ['tag1', 'tag2'],
  })
}

Last updated