I'm looking for a solution to convert an image from a URL into a base64 string using two functions: getImageAsBlob
and toBase64
. The former uses HttpClient
to fetch the image as a Blob, while the latter converts the retrieved Blob into a base64 string.
Could someone please guide me on how best to chain these functions in order to achieve this conversion with just the image URL at hand? Any help would be greatly appreciated!
Here are the functions:
toBase64(blob: Blob): Observable<string> {
const reader = new FileReader();
reader.readAsDataURL(blob);
return fromEvent(reader, 'load')
.pipe(map(() => (reader.result as string)))
}
getImageAsBlob(url: string): Observable<Blob>{
return this.http.get(url,{responseType:'blob'})
}