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.


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


var validCID = “QmUDGFPVro43obZE4qs2XwJKM9EzyvuGqp1oSyTpUWfHiS”
ipfs.files.get(“”+validCID, function (err, files) {
files.forEach((file) => {

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 :

1 Like