I have images and audio files stored in IPFS. When I retrieve the contents in javascript I end up with a Buffer or a tarballed header/body output. How do I convert this back into the original file to use on the website?
const audioCID = CID.parse("QmapPj7koCCMp241CAhwZV413K3FrqVnYdKC2GeTQHsCuF")
const output = await pipe(
ipfs.get(audioCID),
// tarballed,
collect
)
The output I get is:
output [
<Buffer 51 6d 61 70 50 6a 37 6b 6f 43 43 4d 70 32 34 31 43 41 68 77 5a 56 34 31 33 4b 33 46 72 71 56 6e 59 64 4b 43 32 47 65 54 51 48 73 43 75 46 00 00 00 00 ... 1998 more bytes>
]
The output (converting to ASCII) is the CID:
51 6d 61 70 50 6a 37 6b 6f 43 43 4d 70 32 34 31 43 41 68 77 5a 56 34 31 33 4b 33 46 72 71 56 6e 59 64 4b 43 32 47 65 54 51 48 73 43 75 46 00 00 00 00
=
QmapPj7koCCMp241CAhwZV413K3FrqVnYdKC2GeTQHsCuF
Source: https://www.rapidtables.com/convert/number/ascii-hex-bin-dec-converter.html
Solution:
You need to get the content of the IPFS file with ipfs.cat: https://github.com/ipfs/js-ipfs/blob/master/docs/core-api/FILES.md#ipfscatipfspath-options