Reputation: 81
first I created directory using ipfs.files.mkdir
it works fine but doesn't return folder CID or any other information, then I created file to that directory using below code
fs.readFile(temFilePath, async (err1, data) => {
if (err1) throw err1;
let content = await ipfsClient.files.write("/foldername/file.png",data,{create:true});
console.log(content);
res.status(201).send({
message: "file uploaded successfully",
});
});
this code also works and I can see files and folder in IPFS Desktop App but is returns nothing content
is just empty,
my question is how can I get CID of FOLDER or FILEs when creating folders of files,
Upvotes: 1
Views: 542
Reputation: 772
You can get the CID of a file or folder you've added to MFS via ipfs.files.stat("/path/to/whatever")
for example:
let fileInfo = await ipfs.files.stat("/foldername/file.png");
console.log(fileInfo.cid.toString()); // Qm...
Upvotes: 2