首页 > 解决方案 > ipfs-http-client 并同时添加到 ipfs mfs?

问题描述

目前,我有一个负责创建图像的 NodeJS 项目,并且运行良好。唯一的问题是试图弄清楚为什么当您在 ipfs-http-client 请求中使用 ipfs.add() 函数时不会同时将其添加到 ipfs 可变文件存储 (mfs)...

我做了一些搜索,我很好奇这是否会满足我的要求,以便添加的文件会显示在 ipfs 服务器 webui 上。

async function ipfsStoreAsset(db, composite_file_location, fileName, nft_id) {
    // Client Setup
    const client = create()
    try {
        // read file into Buffer
        const content = fs.readFileSync(composite_file_location)
        // create file object using Buffer contents
        const file = { path: fileName, content: content }
        // send file object to ipfs server
        const ipfs_data = await client.add(file).then((ipfs_data) => {
            // get the cid of the uploaded file so we can store it
            let cid = ipfs_data.cid.toString()
            console.log('cid: ' + cid)
            db.query('...storing cid in database...', [cid, nft_id], (err, data, fields) => {
                if(err) {
                    console.log(err)
                }
            })

            return cid
        })
        // Is this going to add the cid that was created to the mfs?
        await ipfs.files.cp(ipfs_data, fileName)})
        
    } catch(err) {
        console.log(err)
    }
}

标签: ipfs

解决方案


推荐阅读