Upon selecting an Image with the Image Picker I receive a content// url
content://com.android.providers.media.documents/document/image%3A139
When using ImageSource.fromAsset() I am returned in empty object. My current goal is to save that image as a new image so I can send it in a req.
I have also tried Utils.android.getApplicationContext().getContentResolver() with no avail.
public onSelectSingleTap() {
return new Promise((resolve, reject) => {
this.isSingleMode = true;
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('Image Source: ', imageSource)
let documentsFolder = knownFolders.documents();
let random = Math.floor(Math.random() * 1000000000);
const filePath: string = path.join(documentsFolder.path, 'image' + random.toString());
let saved = imageSource.saveToFile(filePath, 'jpg')
if (saved) {
const savedFilePath: string = path.join(documentsFolder.path, 'image' + random.toString() + '.jpg');
const file: File = File.fromPath(savedFilePath);
// resolve({file: file, content: selection[0]})
}
})
.catch((err) => console.error("Error loading ImageSource:", err));
}
});
})
}
ImageSource: {"android": {}}
I am not sure if I need to SAVE as a new image or get the actual file path to send it in my request.
Most other answers that I come across are deprecated.