Figma Support Forum

Problem with fetching local image file

I can’t able to fetch local image, but image from url work perfectly!

am I missing something? Thanks in Advance!

Firstly, fetch is used for network requests via the URL, and your local images location is not a URL. Secondly, even if you could load local resources in your plugin somehow (which you can’t do since the plugin is run on the web and it doesn’t have access to your file system), all users will not have these images in their folder so they won’t be able to access them.

You need to either host images on the web somewhere to create the URL or embed them into your plugin code in base64 format. This way your plugin will be able to fetch them or use directly. The second method is not recommended for many images like in your case since the plugin will be too large and will take forever to load.

1 Like

:pray:t2:

I thought of using local resource, since it is a simple private plugin for myself.
Anyhow, I’d embedded all images as base64 array and converted it into Uint8Array when needed.
One catch is that the plugin environment doesn’t have atob() function, so added a polyfill and now it’s working fine.

1 Like