Hello,
I am trying to use the http API to download a file (use /get), however, the downloaded data has extra data at the beginning and the end. I have verified using command (ipfs get ), the file downloaded is correct.
Wondering how to extra the actual file data with http API ?
It seems that the downloaded data started with the multihash value.
Ah, what you are getting back in the HTTP API is a tar archive, not just the content of the file. You might handle it like this:
$ curl 'http://localhost:5001/api/v0/get?arg=<hash>' > output.tar
$ tar -xvf output.tar
# Now you should have a file named with the hash in the current
# directory -- it’s content is the content of the hash
This one’s a little funny because the API can’t just write to disk, but it’s accepting the same commands as the CLI, which can. So it’s effectively simulating writing to disk, then giving you a little archive of what it would have written out.
It gets more complicated because, if the hash is of a single file (not a directory) and you ask for it to be compressed (use the ?compression=true option), you do get back the raw content of the file (well, the gzipped content) and not a tar. But in all other cases, you get a tar.