Skip to main content
Solved

Problem with fetching local image file


mohan_vadivel

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

am I missing something? Thanks in Advance!

Best answer by Gleb

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.

View original

2 replies

Gleb
  • Power Member
  • 4706 replies
  • Answer
  • March 13, 2021

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.


mohan_vadivel

🙏🏼

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.


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