6

Is there an HTTP api equivalent of doing:

ipfs add -r resources/public

where resources/public is a directory with a static website (index.html in the root, css, js etc).

Doing:

 curl -F file=resources/public/index.html "http://$IPFS_HOST:5001/api/v0/add?recursive=true&wrap-with-directory=true"

Will only upload one file:

{"Name":"index.html","Hash":"QmZzbCaCPMEGJBLv7DJCDD2mvgkrvTg78MXYt7cPrQhge6","Size":"1255"}
{"Name":"","Hash":"QmdAGnATEQ1VoytC8L9h5nNepmiZCXv61ob49Dpz5nZVGf","Size":"1312"}

4 Answers 4

5

This is not yet good enough to be the "answer" but this should get you much closer than the existing answers. It's not pretty, but will upload a small directory. It also doesn't work with filenames/dirs that have spaces. I'll update this answer if I am able to improve it.

Is this example we use ipfs.infura.io

cd /your/chosen/path

FILES=$(find * -type f | grep -v ' ' | awk -v q="'" '{print " -F " q "file=@\"" $0 "\";filename=\"" $0 "\"" q}')

curl "https://ipfs.infura.io:5001/api/v0/add?pin=true&recursive=true&wrap-with-directory=true" -X POST -H "Content-Type: multipart/form-data" $FILES
1

I have run into the same problem. I could be wrong, but this is presently not possible to do with Curl. I believe you can use the API inside a Javascript application to upload a path recursively, but with Curl you can only attach a single file, there is no recursive function built in for uploading directories.

If you find a solution do please let me know.

1

You can now use infura ipfs-upload-client which is designed for exactly that and very straightforward

0

You can upload a website in IPFS in its entirety as long as it is static from my understanding.

Parallax websites with anchor links work wonders.

Just do this:

ADD TO IPFS: 1) ipfs add -r [ directory where web files are located ]

PIN IT SO IT DOESN'T DISAPPEAR FROM YOUR NODE IF YOUR DAEMON IS NOT ON: 2) ipfs pin add -r [IPFS hash from above] -Side Note: Make sure you copy the last hash to pin since that will be your root directory

TEST IT ON YOUR NODE: 3) http://localhost:port/ipfs/[IPFS hash]

It should work.

Here is an example of a demo parallax website I uploaded to IPFS. I'm using my own node as a gateway, not the default IPFS gateway:

http://mymobiservices.com:9001/ipfs/QmbaE6vj8xq2inkx5km7stKX3GSjeeKYt2QmB7opNXJhCB

Hope this answers your question. If you need help, let me know.

I'm still learning IPFS so bear with me as I may not know everything related to it.

Pavon

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.