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

Enable File Picker in Blazor Android WebView #4928

Merged
merged 2 commits into from
Feb 26, 2022

Conversation

TanayParikh
Copy link
Contributor

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 your AndroidManifest.xml:

<uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE" />

or update the AssemblyInfo.cs with:

[assembly: UsesPermission(Android.Manifest.Permission.ReadExternalStorage)]

Fixes: #2678

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
@TanayParikh TanayParikh requested a review from a team as a code owner February 25, 2022 16:48
Copy link
Member

@mattleibow mattleibow left a 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.

Copy link
Member

@SteveSandersonMS SteveSandersonMS left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good!

@jsuarezruiz jsuarezruiz added area-blazor Blazor Hybrid / Desktop, BlazorWebView platform/android 🤖 labels Feb 25, 2022
return base.OnShowFileChooser(view, filePathCallback, fileChooserParams);
}

CallFilePickerAsync(filePathCallback, fileChooserParams).FireAndForget();
Copy link
Contributor Author

@TanayParikh TanayParikh Feb 25, 2022

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" />
Copy link
Contributor Author

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.

@TanayParikh TanayParikh merged commit 293772e into main Feb 26, 2022
@TanayParikh TanayParikh deleted the taparik/blazorAndroidFilePicker branch February 26, 2022 00:50
@jamesmontemagno
Copy link
Member

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 :(

See: xamarin/Essentials#1961

@Eilon
Copy link
Member

Eilon commented Feb 26, 2022

I think this PR can stay merged, but I re-opened the bug so we can follow up on this issue.

@TanayParikh
Copy link
Contributor Author

Thanks! Android 30+ compatibility issues should automatically be resolved when xamarin/Essentials#1961 is fixed. Left a comment in #2678 (comment).

@github-actions github-actions bot locked and limited conversation to collaborators Dec 23, 2023
@samhouts samhouts added the fixed-in-6.0.200-preview.14.2 Look for this fix in 6.0.200-preview.14.2! label Aug 2, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
area-blazor Blazor Hybrid / Desktop, BlazorWebView fixed-in-6.0.200-preview.14.2 Look for this fix in 6.0.200-preview.14.2! platform/android 🤖
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[Bug] Maui Blazor InputFile
8 participants