问题描述
我正在使用 ipfs-http-client 模块。
这是我的剧本
async function main() {
const ipfs_client = require('ipfs-http-client');
const client = ipfs_client({recursive: false});
async function addFile(file_data) {
const cid = function (data) {
return client.add(data).then(cid =>{return cid;}).catch(err=>{
console.log(err)})
}
const real_cid = cid(file_data).then(result=>{return result}).catch(err=>{console.log(err)});
return real_cid;
}
const sendFiletoNet = async (file) => {
return await addFile(file);
}
async function getFile(cid){
//error occurs here
for await (const chunk of client.cat(cid)) {
console.info(chunk)
}
return content;
}
const getFileFromNet = async()=>{
return await getFile();
}
getFileFromNet("QmU77sHBUuCT12324e9Re59bNHekpKg1PdCpiVAj3MFLiH").then(r => console.log(r));
module.exports = {sendFiletoNet,getFileFromNet
};
}
main();
(node:22889) UnhandledPromiseRejectionWarning:错误:版本无效,必须是等于 1 或 0 的数字
在 Function.validateCID (/home/chipego/Documents/MedChain/node_modules/ipfs-http-client/node_modules/cids/src/index.js:346:13)
在新的 CID (/home/chipego/Documents/MedChain/node_modules/ipfs-http-client/node_modules/cids/src/index.js:174:9)
在 Object.cat (/home/chipego/Documents/MedChain/node_modules/ipfs-http-client/src/cat.js:16:48)
在 cat.next ()
在 getFile (/home/chipego/Documents/MedChain/logic/ipfs_submit_controller.js:23:26)
在 getFileFromNet (/home/chipego/Documents/MedChain/logic/ipfs_submit_controller.js:30:22)
在主要 (/home/chipego/Documents/MedChain/logic/ipfs_submit_controller.js:32:5)
在对象。 (/home/chipego/Documents/MedChain/logic/ipfs_submit_controller.js:39:1)
在 Module._compile (internal/modules/cjs/loader.js:1063:30)
在 Object.Module._extensions..js (internal/modules/cjs/loader.js:1092:10)
(使用 node --trace-warnings ...
显示警告的创建位置)
(node:22889) UnhandledPromiseRejectionWarning:未处理的承诺拒绝。这个错误要么是因为在没有 catch 块的情况下抛出了异步函数,要么是因为拒绝了一个没有用 .catch() 处理过的承诺。要在未处理的承诺拒绝时终止节点进程,请使用 CLI 标志 --unhandled-rejections=strict
(请参阅 https://nodejs.org/api/cli.html#cli_unhandled_rejections_mode)。 (拒绝编号:2)
(节点:22889)[DEP0018] 弃用警告:不推荐使用未处理的承诺拒绝。将来,未处理的承诺拒绝将使用
解决方法
您的 getFile
函数接受一个参数。您在 getFileFromNet
中调用它,但没有传入参数。