IPFS – How to Add and Read Files from Node?

ipfs

I am currently playing around with IPFS in a docker container. I am able to send HTTP requests to the API using curl. I created a small text file with some text. I would like to add the file with the content to the node and retrieve it afterwards.

So I did:

curl -F file=test.txt http://localhost:5001/api/v0/add 

and received the response

{"Name":"QmYregh1mU7otV4s37hXLKnJ2fk2e8yFbJmU9L9cM6yrQM",
 "Hash":"QmYregh1mU7otV4s37hXLKnJ2fk2e8yFbJmU9L9cM6yrQM",
"Size":"16"}

Now I would like to read the file with and save it on my local machine. I used

 curl http://localhost:5001/api/v0/cat?arg=QmYregh1mU7otV4s37hXLKnJ2fk2e8yFbJmU9L9cM6yrQM 

to retrieve the file. The response is

test.txt

My question is now: How do I get the content of the file?

Best Answer

Try to use cat:

curl -X POST "https://ipfs.elastoscarrier.org/api/v0/cat?arg=QmYregh1mU7otV4s37hXLKnJ2fk2e8yFbJmU9L9cM6yrQM"

This will return the content of the added file.

Related Topic