Uri cannot be used
Categories
(GeckoView :: General, defect)
Tracking
(Not tracked)
People
(Reporter: webdev_support, Unassigned)
Details
User Agent: Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/120.0.0.0 Safari/537.36
Steps to reproduce:
when i open android system file selector, the uri is
content://com.android.providers.media.documents/document/image%3A764691,
getFile() is null
public @NonNull PromptResponse confirm(
@NonNull final Context context, @NonNull final Uri[] uris) {
if (Type.SINGLE == type && (uris == null || uris.length != 1)) {
throw new IllegalArgumentException();
}
final String[] paths = new String[uris != null ? uris.length : 0];
for (int i = 0; i < paths.length; i++) {
paths[i] = getFile(context, uris[i]);
if (paths[i] == null) {
Log.e(LOGTAG, "Only file URIs are supported: " + uris[i]);
}
}
ensureResult().putStringArray("files", paths);
return super.confirm();
}
Comment 1•8 months ago
|
||
The getFile method is not work under newer Android.
Ref: https://stackoverflow.com/questions/61809732/android-data-does-not-exist-on-getcontentresolver
So Geckoview do not have ability to read file content from "content://" scheme , you need to convert to file Uri .
sample code: https://searchfox.org/mozilla-mobile/rev/8bb7243d894ea3c434c2d4372a4c67091f75bff0/firefox-android/android-components/components/browser/engine-gecko/src/main/java/mozilla/components/browser/engine/gecko/prompt/GeckoPromptDelegate.kt#468 and https://searchfox.org/mozilla-mobile/rev/8bb7243d894ea3c434c2d4372a4c67091f75bff0/firefox-android/android-components/components/support/ktx/src/main/java/mozilla/components/support/ktx/android/net/Uri.kt#140
and don't forget to clean up the copied file in cache folder.
Comment 2•8 months ago
|
||
(In reply to jackyzy823 from comment #1)
The getFile method is not work under newer Android.
Ref: https://stackoverflow.com/questions/61809732/android-data-does-not-exist-on-getcontentresolver
So Geckoview do not have ability to read file content from "content://" scheme , you need to convert to file Uri .
sample code: https://searchfox.org/mozilla-mobile/rev/8bb7243d894ea3c434c2d4372a4c67091f75bff0/firefox-android/android-components/components/browser/engine-gecko/src/main/java/mozilla/components/browser/engine/gecko/prompt/GeckoPromptDelegate.kt#468 and https://searchfox.org/mozilla-mobile/rev/8bb7243d894ea3c434c2d4372a4c67091f75bff0/firefox-android/android-components/components/support/ktx/src/main/java/mozilla/components/support/ktx/android/net/Uri.kt#140
and don't forget to clean up the copied file in cache folder.
(In reply to jackyzy823 from comment #1)
The getFile method is not work under newer Android.
Ref: https://stackoverflow.com/questions/61809732/android-data-does-not-exist-on-getcontentresolver
So Geckoview do not have ability to read file content from "content://" scheme , you need to convert to file Uri .
sample code: https://searchfox.org/mozilla-mobile/rev/8bb7243d894ea3c434c2d4372a4c67091f75bff0/firefox-android/android-components/components/browser/engine-gecko/src/main/java/mozilla/components/browser/engine/gecko/prompt/GeckoPromptDelegate.kt#468 and https://searchfox.org/mozilla-mobile/rev/8bb7243d894ea3c434c2d4372a4c67091f75bff0/firefox-android/android-components/components/support/ktx/src/main/java/mozilla/components/support/ktx/android/net/Uri.kt#140
and don't forget to clean up the copied file in cache folder.
If you click the input select files, mobile will be display a file selector, PromptResponse.confirm call getFile(), so PromptResponse.confirm will be get null . It's a bug ? If it's not a bug, how do I do workeraround?
Comment 3•8 months ago
|
||
(In reply to jackyzy823 from comment #1)
The getFile method is not work under newer Android.
Ref: https://stackoverflow.com/questions/61809732/android-data-does-not-exist-on-getcontentresolver
So Geckoview do not have ability to read file content from "content://" scheme , you need to convert to file Uri .
sample code: https://searchfox.org/mozilla-mobile/rev/8bb7243d894ea3c434c2d4372a4c67091f75bff0/firefox-android/android-components/components/browser/engine-gecko/src/main/java/mozilla/components/browser/engine/gecko/prompt/GeckoPromptDelegate.kt#468 and https://searchfox.org/mozilla-mobile/rev/8bb7243d894ea3c434c2d4372a4c67091f75bff0/firefox-android/android-components/components/support/ktx/src/main/java/mozilla/components/support/ktx/android/net/Uri.kt#140
and don't forget to clean up the copied file in cache folder.
If you click the input select files, mobile will be display a file selector, PromptResponse.confirm call getFile(), so PromptResponse.confirm will be get null . It's a bug ? If it's not a bug, how do I do workaround?
Comment 4•8 months ago
|
||
Just pass file:// scheme uri to getFile
Reporter | ||
Comment 5•8 months ago
|
||
(In reply to jackyzy823 from comment #4)
Just pass file:// scheme uri to getFile
Could you tell me why , Isn't Android WebView like this?
Reporter | ||
Comment 6•8 months ago
|
||
What I know is that Android WebView does not rely on file selection_ The data field can be any URI. But GeckoView is strange? Can you tell me why this is?
Comment 7•8 months ago
|
||
WebView or Chromium implement some methods to read content:// scheme file via ContentResolver.openFileDescriptor
GeckoView haven't implement that yet. So you need to do openFileDescriptor manually as i linked
Reporter | ||
Comment 8•8 months ago
|
||
(In reply to jackyzy823 from comment #7)
WebView or Chromium implement some methods to read content:// scheme file via ContentResolver.openFileDescriptor
GeckoView haven't implement that yet. So you need to do openFileDescriptor manually as i linked
Will we consider fixing this issue later?
Comment 9•7 months ago
|
||
The severity field is not set for this bug.
:owlish, could you have a look please?
For more information, please visit BugBot documentation.
Comment 10•6 months ago
|
||
(In reply to jackyzy823 from comment #1)
So Geckoview do not have ability to read file content from "content://" scheme , you need to convert to file Uri .
We do have that ability, but for PDF files only, IIRC
Comment 11•6 months ago
|
||
What exactly is your use case? Are you using GV to write an app?
Updated•6 months ago
|
Comment 12•6 months ago
|
||
We do have that ability, but for PDF files only, IIRC
Quite similar but not the same , content uri for PDF is opened as nsIInputStream
. but i guess file picker require it to be nsIFile
Comment 13•1 month ago
|
||
Clear needinfos that are pending on inactive users.
Inactive users most likely will not respond; if the missing information is essential and cannot be collected another way, the bug maybe should be closed as INCOMPLETE
.
For more information, please visit BugBot documentation.
Description
•