Angular(2) – Base64 Image from URL [on hold]

Home / Uncategorized / Angular(2) – Base64 Image from URL [on hold]

Question:
I need to create a function that receives the URL of an image and returns that image in Base64.

I created the function:getBase64Image(url: string): Promise {
return this.http.get(url, {
headers: this.headers,
responseType: ResponseContentType.Blob
})
.toPromise()
.then(res => {
let blob: Blob = new Blob([res.json()], {
type: res.headers.get("Content-Type")
});

var reader = new FileReader();
reader.readAsDataURL(blob);
reader.onloadend = function(e){
base64 = reader.result;
SOME_CODE
}
})

My problem is on how to return Base64 (reader.result).


Answer:
Here is an answer with example to get image from api and return it as base64.
Read more

Leave a Reply

Your email address will not be published. Required fields are marked *