How to convert Base64 to Image in Scriptable App

367 Views Asked by At

I want to convert the Base64 I get from an API into an image in the iOS scriptable app. Here is my current code:

let image = Image.data(Data.fromBase64String(response.icon))

How could I convert the base64 into an image?

The error:

2021-08-19 12:31:07: Error on line 20:23: TypeError: Image.data is not a function. (In 'Image.data(Data.fromBase64String(response.icon))', 'Image.data' is undefined)
2

There are 2 best solutions below

0
On
let image = await new Request("data:image/png;base64,AAAAAAA").loadImage()
0
On

You do not call the correct initialiser for Image ( It’s .fromData ) :

let image = Image.fromData(Data.fromBase64String(response.icon))