Skip to main content
Question

`exportAsync` function returns Uint8Array instead of SVG string when used with `.then()`


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 await, the 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 await or .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.

Thanks!

0 replies

Be the first to reply!

Reply


Cookie policy

We use cookies to enhance and personalize your experience. If you accept you agree to our full cookie policy. Learn more about our cookies.

 
Cookie settings