Adicionado método para finalizar section ipfs

This commit is contained in:
Luiz F Picolo 2023-06-19 11:01:35 -04:00
parent 3a570d232f
commit 8dd111d680
1 changed files with 11 additions and 3 deletions

View File

@ -22,16 +22,24 @@ class IPFSFileManager {
const fileData = Buffer.concat(chunks);
// Save the file data to a local file
const filePath = `./retrievedFile.txt`;
const filePath = `./retrievedFile.pdf`;
writeFileSync(filePath, fileData);
this.closeIPFS();
console.log('File retrieved from IPFS and saved as:', filePath);
} catch (error) {
console.error('Failed to retrieve the file from IPFS', error);
}
}
async closeIPFS() {
if (this.node) {
await this.node.stop();
console.log('IPFS node connection closed');
}
}
}
const cid = 'QmQzHxipWRHw8xmR8nwbiYasxQzKMh7rdwYwDxpyuoS9jX'; // Replace with the CID of the file you want to retrieve
const cid = 'QmQgGxzWnzjCfouxRiozBiEG3wcsuJGWjtHjv3wurVbJ9s'; // Replace with the CID of the file you want to retrieve
const ipfsFileManager = new IPFSFileManager(cid);
ipfsFileManager.retrieveFileFromIPFS();