diff --git a/lib/presentation/extensions/send_file_extension.dart b/lib/presentation/extensions/send_file_extension.dart index 68be47220b..4042f80559 100644 --- a/lib/presentation/extensions/send_file_extension.dart +++ b/lib/presentation/extensions/send_file_extension.dart @@ -93,17 +93,15 @@ extension SendFileExtension on Room { } final formattedDateTime = DateTime.now().getFormattedCurrentDateTime(); - final targetPath = - await File('${tempDir.path}/$formattedDateTime${fileInfo.fileName}') - .create(); - fileInfo = fileInfo as ImageFileInfo; + final fileName = _generateThumbnailFileName(formattedDateTime, fileInfo); + final targetPath = await _createThumbnailFile(tempDir, fileName); await _generateThumbnail( - fileInfo, + fileInfo as ImageFileInfo, targetPath: targetPath.path, uploadStreamController: uploadStreamController, ); thumbnail = ImageFileInfo( - fileInfo.fileName, + fileName, targetPath.path, await targetPath.length(), width: fileInfo.width, @@ -430,6 +428,15 @@ extension SendFileExtension on Room { return eventId; } + Future _createThumbnailFile(Directory tempDir, String fileName) async => + await File('${tempDir.path}/$fileName').create(); + + String _generateThumbnailFileName( + String formattedDateTime, + FileInfo fileInfo, + ) => + '$formattedDateTime${fileInfo.fileName}.${AppConfig.imageCompressFormmat.name}'; + Future convertHeicToJpgImage(ImageFileInfo fileInfo) async { final convertedFilePath = StorageDirectoryManager.instance.convertFileExtension( @@ -632,7 +639,7 @@ extension SendFileExtension on Room { } uploadStreamController?.add(const Right(GenerateThumbnailSuccess())); return ImageFileInfo( - '${result.name}.${AppConfig.imageCompressFormmat.name}', + result.name, result.path, size, width: width, diff --git a/lib/presentation/extensions/send_file_web_extension.dart b/lib/presentation/extensions/send_file_web_extension.dart index a2a9a66afb..42f08ff02a 100644 --- a/lib/presentation/extensions/send_file_web_extension.dart +++ b/lib/presentation/extensions/send_file_web_extension.dart @@ -19,6 +19,7 @@ import 'package:fluffychat/utils/matrix_sdk_extensions/matrix_file_extension.dar import 'package:flutter_image_compress/flutter_image_compress.dart'; import 'package:matrix/matrix.dart'; import 'package:image/image.dart'; +import 'package:mime/mime.dart'; import 'package:video_player/video_player.dart'; import 'package:video_thumbnail/video_thumbnail.dart'; @@ -169,7 +170,7 @@ extension SendFileWebExtension on Room { : null; if (uploadThumbnail != null && uploadThumbnail.bytes != null) { final uploadThumbnailResponse = await mediaApi.uploadFileWeb( - file: file, + file: uploadThumbnail, cancelToken: cancelToken, onSendProgress: (receive, total) { uploadStreamController?.add( @@ -442,11 +443,12 @@ extension SendFileWebExtension on Room { const Right(GenerateThumbnailSuccess()), ); + final thumbnailFileName = _getVideoThumbnailFileName(originalFile); + return MatrixImageFile( bytes: result, - name: - '${originalFile.name}.${AppConfig.videoThumbnailFormat.name.toLowerCase()}', - mimeType: originalFile.mimeType, + name: thumbnailFileName, + mimeType: lookupMimeType(thumbnailFileName) ?? 'image/jpeg', width: thumbnailBitmap?.width, height: thumbnailBitmap?.height, blurhash: blurHash, @@ -464,6 +466,9 @@ extension SendFileWebExtension on Room { } } + String _getVideoThumbnailFileName(MatrixVideoFile originalFile) => + '${originalFile.name}.${AppConfig.videoThumbnailFormat.name.toLowerCase()}'; + Future _getVideoDuration( MatrixVideoFile originalFile, ) async {