B4J Question [BANano] [SOLVED] Use the BANanoFetch API to Get an Image from a URL

Mashiane

Expert
Licensed User
Longtime User
Hi there

I want to get an image and then perhaps cache it on a IndexDB for later use as a base64 image. I understand there are some .get methods.

1641988473919.png


For this example..

B4X:
const imageUrl = "https://i.picsum.photos/id/566/200/300.jpg?hmac=gDpaVMLNupk7AufUDLFHttohsJ9-C17P7L-QKsVgUQU";

(async () => {
  const response = await fetch(imageUrl)
  const imageBlob = await response.blob()
  const reader = new FileReader();
  reader.readAsDataURL(imageBlob);
  reader.onloadend = () => {
    const base64data = reader.result;
    console.log(base64data);
  }
})()

Will it suffice if I just use BANano.GetFileAsDataURL?

Thanks in advance.

Update: BANano.GetFileAsDataURL is the key.
 
Last edited:
Top