From 0b8806a94815f09000e7cee137c3e021a9a91984 Mon Sep 17 00:00:00 2001 From: Benjamin Kampmann Date: Mon, 9 Dec 2024 15:38:25 +0000 Subject: [PATCH 1/2] Keep the extension of the original file when none was given --- app/lib/features/files/actions/download_file.dart | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/app/lib/features/files/actions/download_file.dart b/app/lib/features/files/actions/download_file.dart index 0a245a62d2d9..7cde29e8018e 100644 --- a/app/lib/features/files/actions/download_file.dart +++ b/app/lib/features/files/actions/download_file.dart @@ -1,5 +1,5 @@ import 'dart:io'; -import 'package:path/path.dart'; +import 'package:path/path.dart' as p; import 'package:file_picker/file_picker.dart'; import 'package:flutter/material.dart'; @@ -8,7 +8,8 @@ import 'package:flutter_easyloading/flutter_easyloading.dart'; Future downloadFile(BuildContext context, File file) async { final lang = L10n.of(context); - final filename = basename(file.path); + final filename = p.basename(file.path); + final extension = p.extension(filename); String? outputFile = await FilePicker.platform.saveFile( dialogTitle: lang.downloadFileDialogTitle, fileName: filename, @@ -18,6 +19,11 @@ Future downloadFile(BuildContext context, File file) async { return false; } + if (p.extension(outputFile).isEmpty) { + // the new file doesn't have an extension, we add the previous one again + outputFile = '$outputFile$extension'; + } + await file.copy(outputFile); EasyLoading.showToast(lang.downloadFileSuccess(outputFile)); return true; From d8cb4f61115e4598d9ddefef00510ffb3fac0fff Mon Sep 17 00:00:00 2001 From: Benjamin Kampmann Date: Mon, 9 Dec 2024 15:51:43 +0000 Subject: [PATCH 2/2] Add Changelog --- .changes/2420-keep-file-extension.md | 1 + 1 file changed, 1 insertion(+) create mode 100644 .changes/2420-keep-file-extension.md diff --git a/.changes/2420-keep-file-extension.md b/.changes/2420-keep-file-extension.md new file mode 100644 index 000000000000..b37ea5a45d0a --- /dev/null +++ b/.changes/2420-keep-file-extension.md @@ -0,0 +1 @@ +- Fix: when downloading as file, keep the extension even if the user removed it to ensure they can open the resulting file. \ No newline at end of file