After I add a file to ipfs using ipfs add hello
- how to do I retrieve the hash for the file if I lose it?
I guess I'm expecting ipfs info <filepath>
or something similar?
After I add a file to ipfs using ipfs add hello
- how to do I retrieve the hash for the file if I lose it?
I guess I'm expecting ipfs info <filepath>
or something similar?
If you want to see what the hash of a file would be, without actually uploading it to IPFS, you can run ipfs add --only-hash
, or ipfs add -n
for short.
Make sure ipfs daemon
is running before proceeding.
ipfs get theHashOfTheItem
in the command line will print out the raw data/ text of the block corresponding to that particular hash
To get a list of objects with the hash that is hosted on your computer, you may run the daemon using ipfs daemon
followed by going to and checking under Files.
I remember reading a way to get the list of hashes via the command line, but I can't seem to remember it. Once I get it, I shall post the details about that here as well.
Not ideal, but checking the information each hash stores, either by using the command shared on top or clicking on the files itself within the browser should let you find the hash you are looking for.
Since you've added the file/folder, it will be pinned to your ipfs repo. Run the command
ipfs pin ls
This will list all the objects of the files/folder pinned to your repo
Spent an hour doing this and turns out you can do a simple ipfs files stat /path/to/object
to get an output like:
$ ipfs files stat /folder-2/text.txt
QmcNsPV7QZFHKb2DNn8GWsU5dtd8zH5DNRa31geC63ceb4
Size: 14
CumulativeSize: 72
ChildBlocks: 1
Type: file
If you want to script this, do a simple | head -n 1
to get the hash.