简体   繁体   English

如何使用 IPFS url 显示图像?

[英]How to display an image using IPFS url?

It would like to know how to display an image from IPFS, I'm having a file that is sent to IPFS and the url is retrieved, so I have tried the below to display the image in a img tag using the url retrieved but it is not showing (I got the broken img icon instead):它想知道如何显示来自 IPFS 的图像,我有一个发送到 IPFS 的文件并检索了 url,所以我尝试了下面的方法来使用检索到的 url 在img标签中显示图像但是它没有显示(我得到了损坏的 img 图标):

<img
  alt="Profile"
  className="rounded-full w-40 h-40"
  src={
   values.url
    ? values.url
    : '/static/img2.png'
  }
/>

The IPFS url is right and is like this: https://ipfs.infura.io/ipfs/QmQRpdqjZM1kuribo1LfH2rHiu27LjXmY34hJDDdy8bKn6 So I tried with src={ values.url ? URL.createObjectURL(values.url) : '/static/img2.png'} IPFS url 是正确的,如下所示: https://ipfs.infura.io/ipfs/QmQRpdqjZM1kuribo1LfH2rHiu27LjXmY34hJDDdy8bKn6 ://ipfs.infura.io/ipfs/QmQRpdqjZM1kuribo1LfH2rHiu27LjXmY34hJDDdy8bKn6 所以我尝试使用src={ values.url ? URL.createObjectURL(values.url) : '/static/img2.png'} src={ values.url ? URL.createObjectURL(values.url) : '/static/img2.png'} , the image is displayed but after I send this url with other info through a metamask transaction, the next error is shown: Uncaught TypeError: Failed to execute 'createObjectURL' on 'URL': Overload resolution failed. src={ values.url ? URL.createObjectURL(values.url) : '/static/img2.png'} ,显示图像,但是在我通过元掩码事务发送此 url 和其他信息后,显示下一个错误: Uncaught TypeError: Failed to execute 'createObjectURL' on 'URL': Overload resolution failed.

Try adding https://ipfs.io in the beginning of your ipfs info as suggested in this document https://docs.ipfs.io/concepts/what-is-ipfs/尝试按照本文档https://docs.ipfs.io/concepts/what-is-ipfs/中的建议在您的 ipfs 信息的开头添加https://ipfs.io

ie IE

ipfs://QmQqzMTavQgT4f4T5v6PWBp7XNKtoPmC9jvn12WPT3gkSE

becomes变成

https://ipfs.io/ipfs/QmQqzMTavQgT4f4T5v6PWBp7XNKtoPmC9jvn12WPT3gkSE

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM