How to retrieve the CID of a block file

Hello,

I have a file in the blocks folder named 5W/CIQIHL6MEMRGC…5WA.data.

How can I retrieve its corresponding CID ?

To be clear I’d like the command ipfs ls CID to return the content of the file.

Have a good day,

Nicolas

You should be able to use these functions: https://github.com/ipfs/go-ipfs-ds-help/blob/v0.1.1/key.go (it needs to be on this version of the library, not latest)

where your datastore key is datastore.NewKey("/CIQYOURFILENAME").

Let me know if that works.

Perfect! Thank you Hector!

I made a small repo for that in case someone else is interested : https://github.com/nlko/ipfs-block-to-cid

(sorry if the style is bad, this is my very first code in go)

1 Like

It seems like now you can use Kubo with either of these commands:

ipfs dag resolve BCIQYOURFILENAME
ipfs cid format -v 0 BCIQYOURFILENAME

But what is the reverse, CidToDsKey?
Also what if a links is like ipfs://bafybeiao4wmudgiy32muigyaes6zs76ks5yikq56yjigaa46ksji4nhoua/11635.json, how to convert it to datastore blocks multihash raw key (if I’m calling it right)?

Answered here: .ipfs/blocks enlarged to 2TB despite MaxStorage setting, discovering cid to ds key conversion - #2 by hector