Cannot preview image with file name containing image extension (jpg,..) and mime type is application/octet-stream
Signed-off-by: dab246 <tdvu@linagora.com>
This commit is contained in:
@@ -1,6 +1,7 @@
|
||||
import 'package:core/data/constants/constant.dart';
|
||||
import 'package:core/domain/preview/document_uti.dart';
|
||||
import 'package:core/domain/preview/supported_preview_file_types.dart';
|
||||
import 'package:core/presentation/extensions/string_extension.dart';
|
||||
import 'package:core/presentation/resources/image_paths.dart';
|
||||
import 'package:http_parser/http_parser.dart';
|
||||
|
||||
@@ -38,7 +39,7 @@ extension MediaTypeExtension on MediaType {
|
||||
return imagePaths.icFilePptx;
|
||||
} else if (isZipFile()) {
|
||||
return imagePaths.icFileZip;
|
||||
} else if (isImageFile()) {
|
||||
} else if (isImageSupportedPreview(fileName: fileName)) {
|
||||
return imagePaths.icFilePng;
|
||||
} else {
|
||||
return imagePaths.icFileEPup;
|
||||
@@ -56,4 +57,11 @@ extension MediaTypeExtension on MediaType {
|
||||
mimeType == Constant.textHtmlMimeType ||
|
||||
(mimeType == Constant.octetStreamMimeType &&
|
||||
fileName?.endsWith(Constant.htmlExtension) == true);
|
||||
|
||||
bool isImageSupportedPreview({required String? fileName}) =>
|
||||
isImageFile() ||
|
||||
(mimeType == Constant.octetStreamMimeType &&
|
||||
fileName != null &&
|
||||
SupportedPreviewFileTypes.imageMimeTypes
|
||||
.contains(fileName.imageMimeType));
|
||||
}
|
||||
|
||||
@@ -40,4 +40,42 @@ extension StringExtension on String {
|
||||
}
|
||||
|
||||
String get firstCharacterToUpperCase => isNotEmpty ? this[0].toUpperCase() : '';
|
||||
|
||||
String get fileExtension {
|
||||
int dotIndex = lastIndexOf('.');
|
||||
if (dotIndex == -1 || dotIndex == length - 1) {
|
||||
return '';
|
||||
}
|
||||
return substring(dotIndex + 1);
|
||||
}
|
||||
|
||||
String get imageMimeType {
|
||||
switch (fileExtension.toLowerCase()) {
|
||||
case 'jpg':
|
||||
case 'jpeg':
|
||||
return 'image/jpeg';
|
||||
case 'png':
|
||||
return 'image/png';
|
||||
case 'gif':
|
||||
return 'image/gif';
|
||||
case 'webp':
|
||||
return 'image/webp';
|
||||
case 'svg':
|
||||
return 'image/svg+xml';
|
||||
case 'bmp':
|
||||
return 'image/bmp';
|
||||
case 'ico':
|
||||
return 'image/x-icon';
|
||||
case 'tif':
|
||||
case 'tiff':
|
||||
return 'image/tiff';
|
||||
case 'heic':
|
||||
case 'heif':
|
||||
return 'image/heif';
|
||||
case 'avif':
|
||||
return 'image/avif';
|
||||
default:
|
||||
return 'application/octet-stream'; // Unknown type
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user