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