0

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);
  });

Console log: enter image description here

Image created by: enter image description here

4
  • In that screenshot the initial header with "Qm..." is an IPFS object header, which is sent over with ipfs.get, you'd want ipfs.cat.
    – Discordian
    Jul 27 at 3:39
  • Thank you for your response, but may be I was unable to clear the things, data return by API is correct but encoded, I just want to decode it (like binary decode or utf8 etc. I don't know). my question was about how do I decode or collect these data to make files and images Jul 27 at 5:13
  • ipfs.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 do ipfs add myimage.png then do ipfs cat cidofmyimage > myimage2.png then myimage.png and myimage2.png will be identical.
    – Discordian
    Jul 27 at 14:55
  • @MubashirFarooq for whatever reason I can't retrieve the CID you're sharing, it's not available whenever I go to look at it. If you give me a CID that's not working for you, that's available (you can back up the data to web3.storage or something to do that), I'll investigate and might be able to get you a solid answer.
    – Discordian
    Jul 27 at 15:20

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.