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 send an image message, you must pass a valid local file URL instance instead. The SDK will resize and process the image object before sending it to the server.

You can also pass an optional caption as part of the message. This caption will be accessible under the data property in the message model, under the caption key. You can add up to 1,000 characters of text caption per message.

let messageId = messageRepository.createImageMessage(withChannelId: "channel-123", 
                                                         imageFile: URL(string: "local-image-path")!, 
                                                           caption: nil, 
                                                         fullImage: true, 
                                                              tags: nil, 
                                                          parentId: nil) { message, error in
     // Handle message creation result.
}

token = messageRepository.getMessage(messageId)?.observe { liveMessage, error in
    // Observe message data changes.
}

Use the fullImage parameter to request to upload the image at its original resolution. Note that this can drastically reduce the speed of message sending, depending on the original image size. If the fullImage is set to false, then the uploaded image size will be up to 1500x1500 pixels.

Last updated