Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Keep the extension of the original file when none was given #2420

Merged
merged 2 commits into from
Dec 10, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .changes/2420-keep-file-extension.md
Original file line number Diff line number Diff line change
@@ -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.
10 changes: 8 additions & 2 deletions app/lib/features/files/actions/download_file.dart
Original file line number Diff line number Diff line change
@@ -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';
Expand All @@ -8,7 +8,8 @@ import 'package:flutter_easyloading/flutter_easyloading.dart';

Future<bool> 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,
Expand All @@ -18,6 +19,11 @@ Future<bool> 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;
Expand Down
Loading