当我尝试访问存储在 IPFS 上的元数据时出现 CORS 错误

发布于 2025-01-16 15:45:12 字数 330 浏览 1 评论 0原文

我尝试使用 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

宣告ˉ结束 2025-01-23 15:45:12

普通浏览器或者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

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文