Pinning a file by its hash

I’m running into an issue with pinning: I have the hash of a file which I want my local go-ipfs node to download and pin. I tried running “ipfs pin add <file_hash>” but this gives me the following error:

Error: pin: merkledag: not found

Upon further reading, I understand that’s happening because the pin command expects an object and not a file hash. However I don’t know how to get the object of a file via its hash! Can anyone please explain how you can download and pin a file when all you know is the hash of that file? Thank you.

I apologize for my silly mistake: The reason it wasn’t working was because my IPFS daemon was not running. I was confused by the fact that you can’t give commands to the console instance that runs the daemon, and since the complaint was about a merkledag I also thought IPFS was expecting something else as a parameter. I ran “ipfs daemon” then “ipfs pin add (hash)” in another console, now it pinned the file.

I’d suggest making such error messages more explicit if possible. In this case, IPFS should have told me “hey you, you need to be running the daemon before issuing a command” rather than just “merkledag not found”. Mainly suggesting this so other users don’t get confused as I was.

1 Like