-
Notifications
You must be signed in to change notification settings - Fork 1.8k
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
Enable File Picker in Blazor Android WebView #4928
Conversation
Enables selecting files within the Blazor WebView (includes both `<InputFile />` and `<input type="file">`). The Blazor Android WebView was updated to utilize the [MAUI Essentials File Picker API](https://docs.microsoft.com/en-us/xamarin/essentials/file-picker?context=xamarin%2Fandroid&tabs=android). Thanks @mattleibow for the tip! Note, you'll need to add the `READ_EXTERNAL_STORAGE` permission to your `AndroidManifest.xml`: ```xml <uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE" /> ``` or update the `AssemblyInfo.cs` with: ```csharp [assembly: UsesPermission(Android.Manifest.Permission.ReadExternalStorage)] ``` Fixes: #2678
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks pretty good to me.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks good!
return base.OnShowFileChooser(view, filePathCallback, fileChooserParams); | ||
} | ||
|
||
CallFilePickerAsync(filePathCallback, fileChooserParams).FireAndForget(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Actual logging (via FireAndForget
's error callback) will be handled via #4441.
@@ -15,7 +15,8 @@ | |||
</ItemGroup> | |||
|
|||
<ItemGroup> | |||
<Compile Include="..\SharedSource\**\*.cs" Link="Windows\SharedSource\%(Filename)%(Extension)"/> | |||
<Compile Include="..\SharedSource\**\*.cs" Link="Windows\SharedSource\%(Filename)%(Extension)" /> | |||
<Compile Include="..\..\..\Core\src\TaskExtensions.cs" Link="Utilities\TaskExtensions.cs" /> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I should just be able to use the TaskExtensions
however they aren't being supported in the net6.0-android context. Added a file reference instead.
One thing to be aware of is if you target Android 30+ which is basically required READ_EXTERNAL_STORAGE is super not really allowed anymore :( |
I think this PR can stay merged, but I re-opened the bug so we can follow up on this issue. |
Thanks! Android 30+ compatibility issues should automatically be resolved when xamarin/Essentials#1961 is fixed. Left a comment in #2678 (comment). |
Enables selecting files within the Blazor WebView (includes both
<InputFile />
and<input type="file">
).The Blazor Android WebView was updated to utilize the MAUI Essentials File Picker API. Thanks @mattleibow for the tip!
Note, you'll need to add the
READ_EXTERNAL_STORAGE
permission to yourAndroidManifest.xml
:or update the
AssemblyInfo.cs
with:Fixes: #2678