Retrieving file from IPFS from node.js

How to retrieve file from ipfs using node.js. I have added a file into ipfs through node.js code and in retrieval process i can’t able to read the image file so cananyone suggest me the soln.

hello,

could you explain a bit how to try to get this image with your image viewer (which path do you use) ?

Regards

var validCID = “QmUDGFPVro43obZE4qs2XwJKM9EzyvuGqp1oSyTpUWfHiS”
ipfs.files.get(“http://ipfs.io/ipfs/”+validCID, function (err, files) {
files.forEach((file) => {
console.log(“file”,file)
console.log(file.content.toString(‘binary’))

var URL = “/home/rpqb-desk-003/vendor_files”
const file1 = validCID;

                    fs.writeFile(URL+"/"+file1, message,'base64',function(err){
                        if (err) throw err;
                        console.log('Data written to file');
    
                    }); // write it back 

})
})

Iam just adding .jpg to the retrieved file from ipfs andd this is the issue

maybe you can see that : https://github.com/ipfs/interface-ipfs-core/blob/master/SPEC/FILES.md#filesgetreadablestream

1 Like