Getting the file names of files I pinned locally

I’d like to know what it is exactly that is pinned locally. this is obviously not possible with content that was pinned based on hash. but can I somehow retrieve the file names of content that was pinned via add from my hard drive?

1 Like

Welcome to the forum, @chaser :wave:

You can use the following command to get more information about a CID:

ipfs dag get [CID]

This will basically render the DAG of the CID.

Alternatively, you can visualise the DAG using https://explore.ipld.io/ (as long as the CID is retrievable).

The problem you might face when you add a single file to IPFS, is that the filename is not added to the dag. For example, the following CID, is of an image

ipfs dag get bafybeibml5uieyxa5tufngvg7fgwbkwvlsuntwbxgtskoqynbt7wlchmfm
# Returns
{"Data":{"/":{"bytes":"CAIYu7xiIICAECCAgBAggIAQIICAECCAgBAggIAQILu8Ag"}},"Links":[{"Hash":{"/":"Qmevts91okBJSZ13BWksZZ2CNVeUufwKTbcrRQCHcnDZ4Z"},"Name":"","Tsize":262158},{"Hash":{"/":"QmdkWRASeEw5m6ZK3DsCtYyr7Vp7FJdJbKVLnzhbECbac9"},"Name":"","Tsize":262158},{"Hash":{"/":"QmfAkyyti6N8w7iNVENRoFxXc4Dy9DVESCVpYs1txq6LaC"},"Name":"","Tsize":262158},{"Hash":{"/":"QmVzgY3zF5SuiunkgxUBBzzAXvLqKBxLrpqYBLkA5Gqy9u"},"Name":"","Tsize":262158},{"Hash":{"/":"QmYQRe6seMnpN87gh5DiSZNAuwirG6tHmqwhzinxYoqUF4"},"Name":"","Tsize":262158},{"Hash":{"/":"Qma46hN6o1AqygGzu8iVSX6RoS5i1jRuq5G4phHnFjh9U3"},"Name":"","Tsize":262158},{"Hash":{"/":"QmZsRbDt6i6LQj7bEdggY3xJokL5cTHsrN6WZdc698yhgW"},"Name":"","Tsize":40521}]}

If you are interested in retaining the information about the filename in the dag, you can use the -w, --wrap-with-directory bool - Wrap files with a directory object. option which will add the filename to the DAG.

For example

ipfs add -w --cid-version=1 practical-explainer-ipfs-gateways-part-2.md

added bafkreihmhz6l4fjqp43cnhgsaw3oecsi2fcr47adirtt5g2g7ymommylea practical-explainer-ipfs-gateways-part-2.md
added bafybeicq43ymchctaila64ifhxebkariywdbtiub7xnm5xldtsyhx5wawa

You get two CIDs returned, one for the file (just the binary representation without the filename) and one for the “folder” which contains a single file with the filename:

If you inspect the second CID, you get:

$ ipfs dag get bafybeicq43ymchctaila64ifhxebkariywdbtiub7xnm5xldtsyhx5wawa
{"Data":{"/":{"bytes":"CAE"}},"Links":[{"Hash":{"/":"bafkreihmhz6l4fjqp43cnhgsaw3oecsi2fcr47adirtt5g2g7ymommylea"},"Name":"practical-explainer-ipfs-gateways-part-2.md","Tsize":21006}]}

Also, everything you add using ipfs add is automatically pinned to your local node.

Hope that helps!