Files stored on the platform can be retrieved directly via the IPFS gateway using the Content Identifier (CID) associated with each file. Here's how to retrieve a file using the CID.
constfs=require('fs');constfetch=require('node-fetch'); // node-fetch must be installed if you are using Node version less than 18constdownloadFile= (cid, path) => {fetch(`https://gateway.lighthouse.storage/ipfs/${cid}`).then(response => {if (response.ok) returnresponse.buffer();thrownewError('Network response was not ok.'); }).then(buffer => {fs.writeFile(path, buffer, () => {console.log(`File saved to ${path}`); }); }).catch(error => {console.error('Failed to save the file:', error); });};// Replace 'CID' with the actual Content Identifier of your file and 'path' with your desired file path.downloadFile('CID','path/to/your/directory/filename.ext');
curlhttps://gateway.lighthouse.storage/ipfs/CID# Make sure to replace 'CID' with the actual Content Identifier of your file.
To retrieve a file using a web browser, simply navigate to the following URL: