I’m trying to use the
exportAsync function to export a Figma node as an SVG file in my plugin. When I use
await, the function returns the SVG code as a string, but when I use
.then(), it returns a
Uint8Array object instead.
After some investigation, I realized that the
exportAsync function returns a
Uint8Array object representing the binary data of the exported file. When I use
Uint8Array object is automatically converted to a string using the default character encoding, but when I use
.then(), I need to manually convert the
Uint8Array to a string.
I suggest that the
exportAsync function should always return the SVG code as a string, regardless of whether it’s used with
.then(). This would make the API more consistent and easier to use.
In the meantime, I found a workaround for this issue by manually converting the
Uint8Array to a string using the following code:
const svgString = String.fromCharCode.apply(null, uint8Array);
I hope this helps other developers who encounter the same issue.