I am working on nativescript and unable to convert local image path to base 64 in native script.
private startSelection(context) {
let that = this;
context
.authorize()
.then(() => {
that.imageAssets = [];
that.imageSrc = null;
return context.present();
})
.then((selection) => {
//console.log("Selection done: " + JSON.stringify(selection));
that.imageSrc = that.isSingleMode && selection.length > 0 ? selection[0] : null;
//console.log( "Hello skdafyvsoa ydfs98a698d8s9" + JSON.stringify(that.imageSrc));
// var base64 = that.imageSrc._android.toBase64String();
// var base64 = that.imageSrc._android;
const image = that.imageSrc._android;
//const imageAsBase64 = image.toBase64String(enums.ImageFormat.png);
//var data = base64Img.base64Sync(image);
// console.log(data);
// set the images to be loaded from the assets with optimal sizes (optimize memory usage)
selection.forEach(function (element) {
element.options.width = that.isSingleMode ? that.previewSize : that.thumbSize;
element.options.height = that.isSingleMode ? that.previewSize : that.thumbSize;
});
that.imageAssets = selection;
this.checkFileupload = true;
}).catch(function (e) {
console.log(e);
});
}
Please help for this code
_handleReaderLoaded(readerEvt) {
var binaryString = readerEvt.target.result;
console.log(binaryString);
this.base64textString= btoa(binaryString);
console.log(btoa(binaryString));
}
I am using angular 6 with native script and want to convert image to base64 and save into the database fro backend i am using sql server.