/ SDKs / Flutter
Chat SDKs Flutter v3
Chat SDKs Flutter
Chat SDKs
Version 3
Sendbird Chat SDK v3 for Flutter is no longer supported as a new version is released. Check out our latest Chat SDK v4

Generate thumbnails of a file message

Copy link

When sending an image file, you can determine whether to create thumbnails of the image to fetch and render into your UI. You can specify up to three different sizes for thumbnail images.

Note: Supported file types are image/* and video/*. The Chat SDK doesn't support creating thumbnails when sending a file message via URL.

The sendFileMessage() method requires passing a FileMessageParams object as an argument to its parameter. It contains an array of ThumbnailSize objects which specify the maximum values of width and height of each thumbnail image. The onCompleted() callback subsequently returns the array of ThumbnailSize objects that contain the URL of each generated thumbnail image file.

A thumbnail image is generated to fit within the bounds of the provided maxWidth and maxHeight. If the size of the original image is smaller than the specified dimensions, the original image will have the width and height of the specified dimensions. The URL of the thumbnail returns the location of the generated thumbnail file within the Sendbird server.

// Send a file message with a raw file.
final file = File();
final params = FileMessageParams.withFile(
        name: FILE_NAME,
        size: FILE_SIZE,
        mimeType: MIME_TYPE,
    ..thumbnailSizes =  [Size(100, 100), Size(40, 40)];
    ..customType = CUSTOM_TYPE
    ..mentionType = MentionType.users // This could be either MentionType.users or MentionType.channel.
    ..mentionedUserIds = ['Jeff', 'Julia']
    ..pushOption = PushNotificationDeliveryOption.normal;

try {
    final preMessage = await channel.sendFileMessage(params: params, onCompleted: (message, error) {
        If (error != null) {
            // Handle error.
        // A file message with detailed configuration is successfully sent to the channel.
        // By using fileMessage.messageId, fileMessage.fileName, fileMessage.customType, and so on,
        // you can access the result object from the Sendbird server to check your FileMessageParams configuration.
        // The current user can receive messages from other users through the onMessageReceived method of an channel event handler.
} catch (e) {
    // Handle error.