[Android] FileOpenPicker returns invalid file path for videos selected
Current behavior
When using FileOpenPicker's PickSingleFIleAsync or PickMultipleFIlesAsync and setting the SuggestedStartLocation property to PickerLocationId.VideosLibrary to select one or multiple videos, the path returned seems invalid on Android. When using FileInfo(string filename) to get the file information like the extension and size of the image, an exception is triggered for Android.
Expected behavior
FileOpenPicker's PickSingleFIleAsync and PickMultipleFIlesAsync should return a valid file path for videos selected.
How to reproduce it (as minimally and precisely as possible)
- Launch the app on Android VideoSelection.zip
- Select "Select videos" button
- Select some videos from the gallery and select "Add"
- Exception should be displayed
Workaround
No response
Works on UWP/WinUI
None
Environment
Uno.WinUI / Uno.WinUI.WebAssembly / Uno.WinUI.Skia
NuGet package version(s)
Uno WInUI : 5.2.108
Affected platforms
Android
IDE
Visual Studio 2022
IDE version
17.9.2
Relevant plugins
No response
Anything else we need to know?
No response
@arianeleonard paths returned by the file picker are supposed to be opaque (the path is not necessarily supposed to be useable through System.IO APIs). You should make a copy of the StorageFile you get through Windows.Storage APIs, such as FileIO and similar first, then make System.IO operations on that copy after.
Out of curiosity, why do you need to interact the file directly?
We use FileInfo to validate the extension and the size of the files selected and to use the OpenRead, OpenText and Open methods.
@arianeleonard Which equivalent Windows.Storage APIs would solve your usecase? We should tackle this by implementing them so that it is transparent to the target platform.
@arianeleonard we're adjusted the documentation in https://github.com/unoplatform/uno/pull/17193 to reflect the fact that the path provided by the AndroidFilePicker cannot return an actual file path (it would otherwise break the write-back feature).
It's best to use the StorageFile APIs to get the information you need, and if you need an actual file on the local storage using System.IO, make sure to create a copy of the file so you can manipulate it directly.