【问题标题】:ipfs.cat(cid) in node js gives error "Error: Invalid version, must be a number equal to 1 or 0 at Function.validateCID"节点 js 中的 ipfs.cat(cid) 给出错误“错误:无效版本,在 Function.validateCID 中必须是等于 1 或 0 的数字”
【发布时间】:2021-04-15 10:42:30
【问题描述】:

我正在使用 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 ... 显示警告的创建位置) (节点:22889)UnhandledPromiseRejectionWarning:未处理的承诺拒绝。此错误源于在没有 catch 块的情况下抛出异步函数内部,或拒绝未使用 .catch() 处理的承诺。要在未处理的 Promise 拒绝时终止节点进程,请使用 CLI 标志 --unhandled-rejections=strict(请参阅 https://nodejs.org/api/cli.html#cli_unhandled_rejections_mode)。 (拒绝编号:2) (节点:22889)[DEP0018] DeprecationWarning:不推荐使用未处理的承诺拒绝。将来,未处理的 Promise 拒绝将终止 Node.js 进程

【问题讨论】:

    标签: javascript node.js web3 ipfs js-ipfs


    【解决方案1】:

    您的getFile 函数接受一个参数。您在 getFileFromNet 中调用它,但没有传入参数。

    【讨论】:

    • 非常感谢。我想这只是睡眠不足。大四项目。
    • 现在我得到了一个 Promise {} 虽然我根据协议处理了承诺
    猜你喜欢
    • 2016-08-25
    • 2018-01-26
    • 1970-01-01
    • 2011-07-05
    • 1970-01-01
    • 2018-07-29
    • 1970-01-01
    • 2017-03-26
    • 1970-01-01
    相关资源
    最近更新 更多