gpt4 book ai didi

javascript - 在 IPFS 中上传数组

转载 作者:行者123 更新时间:2023-12-05 08:08:06 25 4
gpt4 key购买 nike

我知道如何在 IPFS 中上传文件,但如果我想上传简单的 JS 字符串数组怎么办?它返回未知文件,我看不到它的内容

var bufferFile = Buffer.Buffer.from(uuidArray);
ipfs.files.add(bufferFile,(error,result)=>{
console.log(result[0].hash);
})

最佳答案

当然,您使用 addAll添加一个字符串数组,这里有一个完整的例子:

<!DOCTYPE html>
<html lang="en">
<head><title>js-ipfs minimal add example</title>

<script src="https://cdn.jsdelivr.net/npm/ipfs-core@0.15.2/dist/index.min.js"></script>

<script>
var ipfs;
async function main() {
// Create our IPFS node
ipfs = await window.IpfsCore.create();

// Build our "files" array
const files = [{
content: 'ABC'
},{
content: 'DEF'
}];

// Use ipfs.addAll to add each string as it's own CID, then output the results
for await (const result of ipfs.addAll(files)) {
console.log(result);
}
}
main()
</script>
</head>
</html>

输出:

Object { path: "QmNz1UBzpdd4HfZ3qir3aPiRdX5a93XwTuDNyXRc6PKhWW", cid: {…}, size: 11, mode: 420, mtime: undefined }
Object { path: "QmPF99trksANxfkCExBZt9veeitXEcYLtCiacEoh71Eyx4", cid: {…}, size: 11, mode: 420, mtime: undefined }

关于javascript - 在 IPFS 中上传数组,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/52369028/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com