Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can I create a download link for IPFS-hosted files?

I have been playing around with IPFS a lot recently, and have been wondering how to make a download link for files that gives them a custom name. The standard <a> tag download attribute doesn't work:

<a href="http://ipfs.io/ipfs/QmV9tSDx9UiPeWExXEeH6aoDvmihvx6jD5eLb4jbTaKGps" download="ipfs-p2p-file-system.pdf">foo</a>

Is there a way I can work around this by using JavaScript or Jquery? At a last resort I could route the files through the server, but I would prefer not to.

like image 284
xyz Avatar asked Oct 19 '22 21:10

xyz


1 Answers

You can add your file by wrapping it inside a folder and therefore preserving the name of the original file. Try:

$ ipfs add -w example.txt
added QmbFMke1KXqnYyBBWxB74N4c5SBnJMVAiMNRcGu6x1AwQH example.txt
added QmVFDXxAEC5iQ9ptb36dxzpNsQjVatvxhG44wK7PpRzsDE

This way, you can point to the last hash, which is a MerkleDAG Node that points to your file, preserving the name of it. Let me know if this solution works for you :)

like image 122
David Dias Avatar answered Oct 23 '22 10:10

David Dias