How to retrieve filename of file added to ipfs

Say I add an image to my ipfs
$ ipfs add image.png

and get a hash <hash>.
Now, say I want to check what is stored at that hash. How do I do that?

#doesn’t work, image isn’t a dir
$ ipfs ls <hash>

#doesn’t work, image isn’t a text file
$ ipfs cat <hash>

I get that hashing is done on contents, but where is the data extention saved - where is the information on data encoding (png/txt/mp3…)

Thank you for your help.

You only get a directory and corresponding file name retention if you use --wrap-with-directory on the ipfs add command. Otherwise the data extension is not saved anywhere, but the data encoding is derived by rummaging through the actual file contents.

And if you do use --wrap-with-directory, then the returned CID is of the directory and you need to use /ipfs//<file.ext> to retrieve the actual file.

Lynn (D)

# save to file
ipfs cat <hash> > theimagefile
# save to file option 2
ipfs get <hash>
# Try to guess file type
file theimagefile
# Try to get filetype option 2
# open http://localhost:8080/ipfs/hash

# Finally: open file with your favourite tool