FileMessageCreateParams.withFile constructor

FileMessageCreateParams.withFile(
  1. File file, {
  2. String? fileName,
  3. String? data,
  4. String? customType,
  5. MentionType? mentionType,
  6. List<String>? mentionedUserIds,
  7. List<MessageMetaArray>? metaArrays,
  8. int? parentMessageId,
  9. bool? replyToChannel,
  10. PushNotificationDeliveryOption pushNotificationDeliveryOption = PushNotificationDeliveryOption.normal,
  11. bool isPinnedMessage = false,
})

withFile

Implementation

FileMessageCreateParams.withFile(
  File file, {
  String? fileName,
  String? data,
  String? customType,
  MentionType? mentionType,
  List<String>? mentionedUserIds,
  List<MessageMetaArray>? metaArrays,
  int? parentMessageId,
  bool? replyToChannel,
  PushNotificationDeliveryOption pushNotificationDeliveryOption =
      PushNotificationDeliveryOption.normal,
  bool isPinnedMessage = false,
}) : super(
        data: data,
        customType: customType,
        mentionType: mentionType ?? MentionType.users,
        mentionedUserIds: mentionedUserIds,
        metaArrays: metaArrays,
        parentMessageId: parentMessageId,
        replyToChannel: replyToChannel ?? false,
        pushNotificationDeliveryOption: pushNotificationDeliveryOption,
        isPinnedMessage: isPinnedMessage,
      ) {
  if (kIsWeb) {
    sbLog.e(StackTrace.current,
        'FileMessageCreateParams.withFile() is not supported for web');
    throw SendbirdException(
        message: 'FileMessageParams.withFile() is not supported for web');
  }

  String? fileMimeType;
  if (lookupMimeType(file.path) == null) {
    switch (getFileExtension(file.path)) {
      case '.HEIC':
        fileMimeType = 'image/heic';
        break;
      case '.HEIF':
        fileMimeType = 'image/heif';
        break;
      default:
        sbLog.w(StackTrace.current, 'Unknown file mimeType');
        break;
    }
  } else {
    fileMimeType = lookupMimeType(file.path);
  }

  fileInfo = FileInfo.fromFile(
    fileName: fileName ?? 'file',
    file: file,
    mimeType: fileMimeType ?? 'application/octet-stream',
  );
}