'Get Base64 String from an HTTP request

I have this function getImageAsBlob that uses HttpClient to get the image as Blob and function toBase64 which converts the retrieved blob into a base64 string.

How do I chain the functions in order to get the base64 string given that I have only the URL of the image? Thanks for the help!

Below 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'})
    }


Solution 1:[1]

getImageAsBlob("url")
  .pipe(
    mergeMap(blobResponse => toBase64(blobResponse)
  )
  .subscribe(img => ...)

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 Jayesh