You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
This repository has been archived by the owner on May 1, 2024. It is now read-only.
When trying to upload files from a WebView using an HTML input file field the WebChromeClient.FileChooserParams.ParseResult method returns null when multiple files are selected. It does work with a single file.
To attempt to select multiple I added this Extra information in the OnShowFileChooser method, just before the call to start the activity.
chooserIntent.PutExtra(Intent.ExtraAllowMultiple, true);
The file selection Activity does allow for multiple files to be selected. However on the callback the WebChromeClient.FileChooserParams.ParseResult method does not properly parse the multi-selection and returns null.
Load an HTML Page with a file upload control.
Select multiple files
Once selected, no files are reported as selected.
Expected Behavior
Multiple files should be able to be selected.
Actual Behavior
Multiple file selection does not work.
Basic Information
Version with issue: Xamarin.Forms 5.0.0.1931; Xamarin.Forms.Platform.Android 2.0.0.0
For any other poor soul out there struggling with this, I will post an answer to my own question. So apparently when multiple items are selected for upload the returned intent data has information in the ClipData property instead of the Data property. From the examples I posted earlier, you can change the OnActivityResult function, implement the following instead of just calling WebChromeClient.FileChooserParams.ParseResult to get the returned value. I left all of the fully qualified names of everything below for clarity.
Java.Lang.Object? returnedValue;
if (data.ClipData != null)
{
List<Android.Net.Uri> androidUris = new List<Android.Net.Uri>();
for (int i = 0; i < data.ClipData.ItemCount; i++)
{
androidUris.Add(data.ClipData.GetItemAt(i).Uri);
}
This is ridiculous that this API works this way to this day. Here's a Kotlin version
val data:Intent?= result.data
val returnedValue:Array<Uri>?=if(result.resultCode !==Activity.RESULT_OK) {
null
} elseif (data?.clipData !=null) {
// The files are in data.clipData if the user selected multiple files// https://github.com/xamarin/Xamarin.Forms/issues/15341
(0 until(data.clipData!!.itemCount)).map { data.clipData!!.getItemAt(it).uri }.toTypedArray()
} else {
WebChromeClient.FileChooserParams.parseResult(result.resultCode, data)
}
Sign up for freeto subscribe to this conversation on GitHub.
Already have an account?
Sign in.
Description
When trying to upload files from a WebView using an HTML input file field the WebChromeClient.FileChooserParams.ParseResult method returns null when multiple files are selected. It does work with a single file.
Steps to Reproduce
This article nicely outlines all of the steps necessary to make the File selector appear when a input file is clicked on a web page within a WebView on Android
https://localcoder.org/uploading-files-using-a-webview-in-xamarin-android-app
This does work for single file selection.
To attempt to select multiple I added this Extra information in the OnShowFileChooser method, just before the call to start the activity.
chooserIntent.PutExtra(Intent.ExtraAllowMultiple, true);
The file selection Activity does allow for multiple files to be selected. However on the callback the WebChromeClient.FileChooserParams.ParseResult method does not properly parse the multi-selection and returns null.
Expected Behavior
Multiple files should be able to be selected.
Actual Behavior
Multiple file selection does not work.
Basic Information
Environment
Show/Hide Visual Studio info
Workaround
Nothing simple.
The text was updated successfully, but these errors were encountered: