From 563629142d560c7654a18472395c76b7533cae26 Mon Sep 17 00:00:00 2001 From: Karthikeyan S Date: Tue, 11 Mar 2025 17:00:12 +0530 Subject: [PATCH] fix: incorrect mimeType for files when downloading --- lib/src/event.dart | 6 +++++- lib/src/utils/matrix_file.dart | 7 ++++--- 2 files changed, 9 insertions(+), 4 deletions(-) diff --git a/lib/src/event.dart b/lib/src/event.dart index f682dc7f..d45176fd 100644 --- a/lib/src/event.dart +++ b/lib/src/event.dart @@ -792,7 +792,11 @@ class Event extends MatrixEvent { throw ('Unable to decrypt file'); } } - return MatrixFile(bytes: uint8list, name: body); + return MatrixFile( + bytes: uint8list, + name: body, + mimeType: attachmentMimetype, + ); } /// Returns if this is a known event type. diff --git a/lib/src/utils/matrix_file.dart b/lib/src/utils/matrix_file.dart index 288eec01..b82adbbd 100644 --- a/lib/src/utils/matrix_file.dart +++ b/lib/src/utils/matrix_file.dart @@ -41,9 +41,10 @@ class MatrixFile { } MatrixFile({required this.bytes, required String name, String? mimeType}) - : mimeType = mimeType ?? - lookupMimeType(name, headerBytes: bytes) ?? - 'application/octet-stream', + : mimeType = mimeType != null && mimeType.isNotEmpty + ? mimeType + : lookupMimeType(name, headerBytes: bytes) ?? + 'application/octet-stream', name = name.split('/').last; /// derivatives the MIME type from the [bytes] and correspondingly creates a