Can I add files to a DAG and then reference each files CID over IPFS?

Let’s say I have three files that I’d like to host on another IPFS node. If I add these three files to a DAG and then pin the DAG’s CID on the other node would that also pin the three files in a way that I could retrieve them individually by their CIDs still?

I’m just trying to figure out the best way to pin several files using one CID, but preferably without having to compress the files into a compressed file. Does adding the files to a DAG solve this?

Not sure what you mean by “several files using one CID”. Each file will have it’s own CID. You don’t really need to think about the DAG nodes, if you just care about files.

Once you have a CID and then pin the file, it’s guaranteed to be available to everyone across the web as long as the gateway it’s pinned on stays available/reachable.

Is there a way to reference several files using one CID though? The reason I ask is because filecoin doesn’t like accepting small files, so I’m trying to combine the files so that a single CID that I give to filecoin will reference all three files. If that makes sense? I was told to either use a DAG or use a compressed archive, but I’d rather not compress the files because I’ll have to uncompress them before I can actually use them.

Ok I got it now. Yeah your best option if you don’t want to put them in a TAR/ZIP is to use an MFS folder I think, or at least an IPFS folder anyway. I have never used folders, but it’s a very common thing to wrap files onto a folder, and yes the folder will get it’s own CID which can be used to get all three files.

This basic example is about a CID that contains several files:


Awesome that makes sense! Thanks for explaining!

1 Like

@wclayf is right about folders. in fact, you can convince yourself of this by looking at the folder he referenced using the command ipfs object get /ipfs/QmYwAPJzv5CZsnA625s3Xf2nemtYgPpHdWEz79ojWnPbdG/ to show you the underlying IPLD node that makes the directory. you will see in that node, links to all the files it contains, and their own hashes. this is the root node of the merkle dag that holds your data.