uno icon indicating copy to clipboard operation
uno copied to clipboard

[Android] FileOpenPicker returns invalid file path for videos selected

Open arianeleonard opened this issue 1 year ago • 3 comments

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)

  1. Launch the app on Android VideoSelection.zip
  2. Select "Select videos" button
  3. Select some videos from the gallery and select "Add"
  4. 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 avatar May 06 '24 15:05 arianeleonard

@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?

jeromelaban avatar May 08 '24 14:05 jeromelaban

We use FileInfo to validate the extension and the size of the files selected and to use the OpenRead, OpenText and Open methods.

arianeleonard avatar May 08 '24 15:05 arianeleonard

@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.

MartinZikmund avatar May 08 '24 15:05 MartinZikmund

@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.

jeromelaban avatar Jun 18 '24 12:06 jeromelaban