11

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?

significance
  • 4,797
  • 8
  • 38
  • 57

5 Answers5

10

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.

Stan James
  • 2,535
  • 1
  • 28
  • 35
Lawrence
  • 10,142
  • 5
  • 39
  • 51
4

just run ipfs add hello again...

significance
  • 4,797
  • 8
  • 38
  • 57
2

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.

http://localhost:5001/webui

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.

Varun Agarwal
  • 1,587
  • 14
  • 29
1

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

Arun
  • 969
  • 7
  • 17
1

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.