当我尝试访问存储在 IPFS 上的元数据时出现 CORS 错误
我尝试使用 axios 获取存储在 NFT.storage 上的元数据,但每次都会收到此错误:
从源“http://127.0.0.1:3000”访问“ipfs://bafyreib6hf354pwtnwxdmfllegogffvkv2dzsrgbithvjbzzewu757bxay/metadata.json”处的 XMLHttpRequest 已被 CORS 策略阻止:仅支持以下协议方案的跨源请求:http、数据、铬、 chrome 扩展、chrome 不受信任、https。
我以前做web2开发的时候已经解决过很多次这个问题了,但是不知道这里该怎么做。
I am trying to fetch the metadata I stored on NFT.storage using axios, but each time I get this error:
Access to XMLHttpRequest at 'ipfs://bafyreib6hf354pwtnwxdmfllegogffvkv2dzsrgbithvjbzzewu757bxay/metadata.json' from origin 'http://127.0.0.1:3000' has been blocked by CORS policy: Cross origin requests are only supported for protocol schemes: http, data, chrome, chrome-extension, chrome-untrusted, https.
I have solved this issue many times when I used to do web2 development but don't know how to do this here.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
普通浏览器或者js无法直接访问
ipfs://
前缀的内容。相反,您必须通过 网关 访问它。一些流行的网关是 ipfs.io、pinata、moralis。
这是 ipfs 网关的示例用法:
https://ipfs.io/ipfs/bafyreib6hf354pwtnwxdmfllegogffvkv2dzsrgbithvjbzzewu757bxay/metadata.json
尝试向此网址发出 axios 请求
You cannot directly access
ipfs://
prefixed content from a normal browser or js. Instead, you'd have to access it through a gateway.Some popular gateways are ipfs.io, pinata, moralis..
This is an example usage of an ipfs gateway:
https://ipfs.io/ipfs/bafyreib6hf354pwtnwxdmfllegogffvkv2dzsrgbithvjbzzewu757bxay/metadata.json
Try making your axios request to this url