Reputation: 714
I am trying to read json
file from local, but as a response I am getting an error look like this
Fetch API cannot load file:///var/www/desktop-electron//dashboard/bnb.json. URL scheme "file" is not supported
Here is my code
fetch(`${drr}/dashboard/bnb.json`)
.then(res => res.json())
.then(res => {
this.currency = res;
Object.assign(this.stock, res.pairs[0]);
Object.assign(this.header, res.pairs[0]);
this.header.name = res.name;
}).catch(function(e) { console.log(e) });
I have read all solutions which from google ,but can not solve the problem!
Upvotes: 0
Views: 1866
Reputation: 4641
Native fetch (Chromium) doesn't support to load resources from local via file protocol. In short you can't, you need to use other way around (like fs.readfile, or some other means) or host json to remote endpoint to use fetch.
Upvotes: 0
Reputation: 336
have you tried to omit the "file://" scheme altogether? Also first try to wrap the URI in a Request Object, like described here
fetch(new Request(URI))
Upvotes: 1