I am implementing Kubo RPC API
in Node JS to upload files to IPFS, Uploads works, but when I try to get content of file using ifps.cat(CID)
it returns may be plain text, stream or chunks (may be encoded, I don't know which type of encoding is it.).
My question is how do I convert this data to a readable image or pdf, below code create image which is unreadable or pdf which is empty.
node JS Code:
axios.post('http://127.0.0.1:5001/api/v0/cat?arg=QmYjChbAEthEYz7qiR8XHHFS9uRZcMsfZVukpAcCF4q6xw')
.then(async function (response) {
console.log(response.data);
fs.writeFile("./myfile.png",response.data, (err) => {
if (err) throw err;
res.status(200).send("files saved.");
});
})
.catch(function (error) {
console.log(error);
res.status(500).send(error);
});
ipfs.get
, you'd wantipfs.cat
. - Discordianipfs.cat
returns the file exactly as it was when it was added to IPFS, without any encoding. If there's encoding, it would have had to have been encoded when it was added. If I doipfs add myimage.png
then doipfs cat cidofmyimage > myimage2.png
thenmyimage.png
andmyimage2.png
will be identical. - Discordian89 50 4E 47 0D 0A 1A 0A 00 00 00 0D 49 48 44 52
which if you look at your image is a direct match since 0D 0A is the first line EOL \x89 \x50 \x4E \x47\r\n followed by the \x1A(escape)\n followed by three \x00 and \rIHDR thus data: is binary.png, but again your console is text with diamonds, so save it as binary - K J