Calculating IPFS Multihash Of Files Without Uploading Them To IPFS

Currently I’m working on letting my users upload files to IPFS. I’m trying to create a method of uploading very large files, while being able to give the user the ipfs multihash that would refer to their file before it’s actually uploaded to my IPFS node. For example, say they upload a 100GB file. I would like to not have to wait for that file to be uploaded, and processed by IPFS before being able to give them the IPFS Multihash that refers to their file. My goal with this is that it’ll be faster to immediately give them their content hash, and let them be on their way, then have to wait for my IPFS node, and subsequently my IPFS cluster to pin that 100GB file.

My original idea was to try to use this package https://github.com/ipfs/go-cid however I can’t seem to find a way to replicate the method by which IPFS generates multihashes.

1 Like

You can try using ipfs add --only-hash first. This will just compute the hash without adding the file.

1 Like

Okay I’ll see how that works and try to modify that to create an API callable version.

The discussion linked below is similar and talks about some of the considerations with trying to do this:

2 Likes

It is already an API method: IPFS Documentation | IPFS Docs (the CLI client calls the API when the daemon is running).

1 Like