Repository navigation
Description
Current behavior 🐛
When the browser has no File System Access API (Firefox, Safari, Brave and others), FileSavePicker.PickSaveFileAsync falls back to the download picker. That fallback always appends the first extension of the first FileTypeChoices entry to SuggestedFileName, even when the name already ends with it:
SuggestedFileName |
FileTypeChoices |
Download name |
|---|---|---|
Report.pdf |
PDF: .pdf |
Report.pdf.pdf |
Report.PDF |
PDF: .pdf |
Report.PDF.pdf |
Report.txt |
PDF: .pdf; Text: .txt |
Report.txt.pdf |
This was seen in an app in the browser: the user gets a file named Report.pdf.pdf.
The File System Access API path (showSaveFilePicker, in Chromium browsers) doesn't double it: FileSavePicker.ts appends the first extension only when the name doesn't already end with one of the choices' extensions (case-insensitive). The Android picker uses the same rule. On Windows, the save dialog adds its default extension only when the file name has none (as documented for lpstrDefExt), so Report.pdf stays Report.pdf there too.
Expected behavior 🎯
The download picker names the file as the native picker suggests it: a name that already ends with one of the FileTypeChoices extensions (case-insensitive) is kept, with its own casing. Otherwise the first extension is appended, as it is today:
SuggestedFileName |
FileTypeChoices |
Download name |
|---|---|---|
Report.pdf |
PDF: .pdf |
Report.pdf |
Report.PDF |
PDF: .pdf |
Report.PDF |
Report.txt |
PDF: .pdf; Text: .txt |
Report.txt |
Report |
PDF: .pdf |
Report.pdf (unchanged) |
Report.txt |
PDF: .pdf |
Report.txt.pdf (unchanged, as on the native path) |
How to reproduce it (as minimally and precisely as possible) 🔬
In a WebAssembly app, in Firefox (or in any browser with WinRTFeatureConfiguration.Storage.Pickers.WasmConfiguration = WasmPickerConfiguration.DownloadUpload):
var picker = new FileSavePicker
{
SuggestedStartLocation = PickerLocationId.DocumentsLibrary,
SuggestedFileName = "Report.pdf",
};
picker.FileTypeChoices.Add("PDF", new List<string> { ".pdf" });
var file = await picker.PickSaveFileAsync();
// file.Name is "Report.pdf.pdf"
CachedFileManager.DeferUpdates(file);
await FileIO.WriteTextAsync(file, "Hello");
await CachedFileManager.CompleteUpdatesAsync(file); // downloads "Report.pdf.pdf"Workaround 🛠️
On WebAssembly, leave the extension off SuggestedFileName. Both the download picker and the native picker then append the first choice's extension.
Affected platforms 📱💻🖥️
WebAssembly
Uno.Sdk version (and other relevant versions) 📦
Seen with Uno.Sdk 6.8. The code is the same on master: DownloadPickerPickSaveFileAsync in src/Uno.WinRT/Storage/Pickers/FileSavePicker.wasm.cs has appended the extension unconditionally since 2021.
IDE version 🧑💻
Not IDE-related.
Anything else we need to know? 💬
I have a fix with runtime tests ready and will open a PR.
Activity
test(wasm): Link the download name tests to unoplatform#25671
test(wasm): Link the download name tests to unoplatform#25671 (port)