I have a function that converts a image to base64 and returns the value.
In .ts file:--
async getBase64ImageFromUrl(imageUrl) {
const proxyurl = "https://cors-anywhere.herokuapp.com/";
var res = await fetch(proxyurl+imageUrl);
var blob = await res.blob();
return new Promise((resolve, reject) => {
var reader = new FileReader();
reader.addEventListener("load", function () {
// console.log(reader.result); /// getting the base64 image URL here.
resolve(reader.result);
return;
}, false);
reader.onerror = () => {
return reject(this);
};
reader.readAsDataURL(blob);
})
}
I wanted to get the value in in the HTML, I know I am doing something wrong
<img class="w-100" [src]="getBase64ImageFromUrl('https://dam.dev.catalog.1worldsync.com/im/img/GCP-5129882489061376')"/>
I know I am doing it wrong, wanted to know the right way to do this.