[SOLVED] Return the IPFS hash on uploadFolder endpoint

Right now the Moralis.Web3API.storage.uploadFolder endpoint returns something like this:

[
  {
    "path": "https://ipfs.moralis.io/QmPQ3YJ3hgfsBzJ1U4MGyV2C1GhDy6MWCENr1qMdMpKVnY/moralis/logo.jpg"
  }
]

In my code I need the IPFS hash after I got the response. So it would be nice if the response can be extended to get something like this:

[
  {
    "path": "https://ipfs.moralis.io/QmPQ3YJ3hgfsBzJ1U4MGyV2C1GhDy6MWCENr1qMdMpKVnY/moralis/logo.jpg",
    "hash": "QmPQ3YJ3hgfsBzJ1U4MGyV2C1GhDy6MWCENr1qMdMpKVnY"
  }
]

Because currently I don’t know if there is a reliable way to extract the hash from the URL.

You could propose it on roadmap.moralis.io

It should be possible to extract the hash from the url too. It may be easier to use pinata to upload a folder on ipfs.

Ok I have submitted a proposal.

I think there is no reliable method to extract the hash, because Moralis could theoretically change the URL format again. My response example is from the documentation and as you can see that is already an old URL format. The new format is https://ipfs.moralis.io:2053/ipfs/… So it would be bad to build something that extracts the hash from the current format, and then the format changes again in the future.

you should be able to do a simple string manipulation

I’m not aware of the path name change, but that shouldn’t be too big of a problem too

but f you want the hash definitely it’ll be more convenient, unfortunately not possible at the moment :raised_hands:

Yes I found a solution. I split the URL at the “/” and then take the 3rd last part, because my URL is built that way:

…/QmPQ3YJ3hgfsBzJ1U4MGyV2C1GhDy6MWCENr1qMdMpKVnY/metadata/{id}.json

So the part before the hash doesnt matter and the part after the hash should only change if I do it in my code. So I think I’m fine with this solution.

2 Likes

I just used this piece of code in my project to extract CID from the response. And it works fine. Hope this helps.

imageCid = res.data[0].path.substring(34, 80)