Unity: Downloading Image from IPFS

Hello, I’m trying to pull NFT images into Unity. For some of the NFT collections (that are hosted traditionally) I have no issues because I use UnityWebRequests and pass in the URL. But for the collections that are using IPFS, I am having no luck. I get this error:

Curl error 1: Protocol “ipfs” not supported or disabled in libcurl

I saw there is a way for Moralis to interact directly with IPFS, but that was for javascript. Could you please advice the best way to get actual image data from IPFS into Unity?

Thank you

You can use a simple http link for ipfs too, you can convert from ipfs url to a http url. When you upload a file to IPFS twitch Moralis you get a http url back.

1 Like

Hi Cryptokid, thank you for the quick reply. That’s great to know! That conversion from ipfs url to http url, is that only for file you yourself upload? Or is there a Moralis function that will do this for ipfs file from something you did not upload - like if I’m pulling various collection images for a marketplace for example.

Thank you

there isn’t a function in Moralis SDK that does that conversion, but it should work with any IPFS hash, not only with the files that you uploaded, and you can also use other IPFS providers like ipfs.io or cloudflare

1 Like

Got it! I just did some parsing and was able to add an IPFS gateway address to the IPFS hash and it worked great. Thank you for explaining!

Do you know if there is any way to know what file type a hash represents? Some collection have SVG files instead of pngs etc. I need to do a check inside Unity to see if its a regular Texture2D or if I need to treat the image as an SVG.

Thank you

from what I know you can only check that file type by reading first few bytes from the downloaded data and by interpreting those few bytes

Hello, could you share with me how you solved it? I am having the same problem

If this is within Unity you can do something like this.

So get the CID from ipfs://cidhere, etc. and then add a gateway in front like https://gateway.moralisipfs.com/ipfs/cidhere.