[@nativescript/imagepicker] Returns `ImageAsset` with `content://` scheme that can't be loaded with `ImageSource.fromAsset`
See original GitHub issueVersions
@nativescript/core: 7.3.0
@nativescript/android: 7.0.1
@nativescript/imagepicker: 1.0.5
Problem
Using @nativescript/imagepicker
in Android 10, the returned selected image has the following form when logged to console:
{
"_observers": {},
"_options": {
"keepAspectRatio": true,
"autoScaleFactor": true
},
"_android": "content://com.android.providers.media.documents/document/image%3A29"
When trying to load this ImageAsset
into an ImageSource
with ImageSource.fromAsset
I get an Asset 'content://com.android.providers.media.documents/document/image%3A29' cannot be found.
error.
Example code
let context = imagepicker.create({
mode: "single",
mediaType: ImagePickerMediaType.Image,
});
context
.authorize()
.then(() => {
return context.present();
})
.then((selection) => {
if (selection.length > 0) {
ImageSource.fromAsset(selection[0])
.then((imageSource) => {
console.log("ImageSource loaded:", imageSource);
})
.catch((err) => console.error("Error loading ImageSource:", err));
}
});
Is this a bug, or is there another way to get an ImageSource
from the result of the imagepicker selection?
Issue Analytics
- State:
- Created 2 years ago
- Comments:8 (4 by maintainers)
Top Results From Across the Web
Nativescript imageSource.fromAsset getImageAsync error
I'm using nativescript-imagepicker for the selection of the image : let context = imagePicker.create({ mode : "single" }); context.authorize() .
Read more >ImageSource.fromAsset() memory leak on iOS #9694 - GitHub
Issue Description On iOS my app is crashing because it eats all the memory. I used Xcode profiler to find out what's causing...
Read more >Class ImageSource - NativeScript Docs
Loads this instance from the specified base64 encoded string asynchronously. Parameters. source: string. The Base64 string to load the image from. Returns ......
Read more >Nativescript imagepicker not working in iOS - Anycodings.com
I am now saving the image to a temporary anycodings_nativescript location and it is still not working in iOS. anycodings_nativescript It works ...
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
As a heads up the issue looks to be this line: https://github.com/NativeScript/plugins/blob/master/packages/imagepicker/index.android.ts#L198
I’m getting these Uris returned on API Level 30 devices which suggests this line is causing the problem. Manually setting this to true fixed the issue for API Level 30 devices but I can’t be sure of the impact.
To workaround the problem in my project I’ve:
UriHelper
into my own code as an exported class.UriHelper._calculateFileUri
and try again.Looks something like this:
Same here. I am using @jamescodesthings hack while waiting for a fix