FileMessageParams.withFileBytes constructor Null safety

FileMessageParams.withFileBytes(
  1. Uint8List data,
  2. {String? name,
  3. String? fileExtensionType}
)

Implementation

FileMessageParams.withFileBytes(Uint8List data,
    {String? name, String? fileExtensionType}) {
  String fileType = "";
  final mime = lookupMimeType('', headerBytes: data);

  if (mime == null) {
    if (fileExtensionType != null) {
      fileType = fileExtensionType;
    } else {
      logger.e(StackTrace.current, "File Extension Type UNKNOWN");
      throw Exception(
          "File Extension Type UNKNOWN. Please include `fileExtensionType`");
    }
  } else {
    fileType = mime;
  }

  uploadFile = FileInfo.fromBytes(
    name: name ?? 'my_file',
    fileBytes: data,
    mimeType: fileType,
  );
}