Can I get the size of the file before downloading it throught IPFS?

Assume that someone gives me a CID and claims that the file pointed by this CID contains the content I need, but, in fact, this file is useless and is gigantic. That guy just wants to waste my disk space and network bandwidth. So can I check the size of the file before dowloading via the CID?

You will start downloading the file block by block (I think the default maximum size you will accept is 1 MB? To be checked.).

After the first block, you will realize it’s not the expected result and ask again. After the second time (I think), you will drop the connection. Hopefully, you will be able to find another provider for the data. At the end of the day, you will have wasted 2MB on that guy, and not the whole size of the file.

1 Like

OK, so let’s say the max file size I would accept is 10MB, then I only need to download at most 10 blocks, and then drop the connection no matter what. So how can I drop the connection programmatically? Are there any commands, APIs or configuration let me do that?

You can’t know what KIND it is but with any file larger than 1 mebibyte (could be a raw block otherwise) you can do ipfs dag stat <CID> and get the size.

1 Like