To download IPFS objects using the HTTP API you need to use GET
. As you can read in the docs.
/api/v0/get
Download IPFS objects.
Arguments
arg
[string]: The path to the IPFS object(s) to be outputted. Required: yes.
output
[string]: The path where the output should be stored. Required: no.
archive
[bool]: Output a TAR archive. Required: no.
compress
[bool]: Compress the output with GZIP compression. Required: no.
compression-level
[int]: The level of compression (1-9). Required: no.
For your example, something like the following should work:
$ curl "http://localhost:5001/api/v0/get?arg=QmYregh1mU7otV4s37hXLKnJ2fk2e8yFbJmU9L9cM6yrQM&archive=false" >> myfile
% Total % Received % Xferd Average Speed Time Time Time Current
Dload Upload Total Spent Left Speed
100 2048 0 2048 0 0 666k 0 --:--:-- --:--:-- --:--:-- 666k
$ cat myfile
QmYregh1mU7otV4s37hXLKnJ2fk2e8yFbJmU9L9cM6yrQM0000644000000000000000000000001013567560642017027 0ustar0000000000000000test.txt
The content (test.txt
) is shown at the end of the line. As you can see, I've used only one argument (archive=false
) and doesn't work because I'm still getting a tar
file. Please read about that here.
For your interest, it's possible to download objects using CLI commands:
get <ref> Download IPFS objects
Example:
$ ipfs get QmYregh1mU7otV4s37hXLKnJ2fk2e8yFbJmU9L9cM6yrQM
Saving file(s) to QmYregh1mU7otV4s37hXLKnJ2fk2e8yFbJmU9L9cM6yrQM
8 B / 8 B [========================================================================================================================================================] 100.00% 0s
$ cat QmYregh1mU7otV4s37hXLKnJ2fk2e8yFbJmU9L9cM6yrQM
test.txt
toString()
on the received payload