5

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.

James A Mohler
  • 11,060
  • 15
  • 46
  • 72
xyz
  • 113
  • 9

2 Answers2

2

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 :)

David Dias
  • 1,792
  • 3
  • 16
  • 28
  • This works very well for a static set of files, but by adding files into the folder, the hash changes each time, i.e: – xyz Jan 08 '16 at 20:36
  • @Will thats the hole point of the hash, but you can publish it `ipfs name publish QmVFDXxAEC5iQ9ptb36dxzpNsQjVatvxhG44wK7PpRzsDE` and then use this link : /ipns/ – yellowsir Jan 13 '16 at 22:05
  • Did this answered your question Will? Let me know if you still need help. – David Dias Apr 12 '16 at 21:34
-1

Try adding "?filename=filename.pdf&download=true" at the end of CID.

Like so:

https://ipfs.io/ipfs/QmV9tSDx9UiPeWExXEeH6aoDvmihvx6jD5eLb4jbTaKGps?filename=filename.pdf&download=true
Luca Kiebel
  • 9,790
  • 7
  • 29
  • 44