伙计们。几个月前,我添加了用于上传文件的ipfs,它们都正常工作,但一周前我遇到了问题,无法解决。我尝试将文件发送到IPFS并获取文件哈希。
就像这样。连接指规数:
ipfs = await Ipfs.create({
config: {
Bootstrap: [
'/dns4/ams-1.bootstrap.libp2p.io/tcp/443/wss/ipfs/QmSoLer265NRgSp2LA3dPaeykiS1J6DifTC88f5uVQKNAd',
'/dns4/lon-1.bootstrap.libp2p.io/tcp/443/wss/ipfs/QmSoLMeWqB7YGVLJN3pNLQpmmEk35v6wYtsMGLzSr5QBU3',
'/dns4/sfo-3.bootstrap.libp2p.io/tcp/443/wss/ipfs/QmSoLPppuBtQSGwKDZT2M73ULpjvfd3aZ6ha4oFGL1KrGM',
'/dns4/node0.preload.ipfs.io/tcp/443/wss/ipfs/QmZMxNdpMkewiVZLMRxaNxUeZpDUb34pWjZ1kZvsd16Zic',
'/dns4/node1.preload.ipfs.io/tcp/443/wss/ipfs/Qmbut9Ywz9YEDrz8ySBSgWyJk41Uvm2QJPhwDJzJyGFsD6'
]
}
});
console.timeEnd('IPFS Started');然后试着发送文件
const {ipfs, ipfsInitError} = useIpfs({commands: ['id']});
const addToIpfs = async (file) => {
const hashOfFile = await ipfs.add(file);
return hashOfFile[0].path;
};所以,当我试图上传时,我有错误
Unhandled Rejection (TypeError): undefined is not an object (evaluating ‘hashOfFile[0].path’)
in hashOfFile return function
AsyncGenerator {_invoke: function, next: function, throw: function, return: function, Symbol(Symbol.asyncIterator): function}
``
earlier it was hash of file.
could you help me?发布于 2020-04-08 12:23:49
在GitHub上,我得到了开发人员的答复
以前ipfs.add返回了一个数组,这很好,除非您添加了大量文件,在这种情况下,您的进程可能会耗尽内存。现在,正如您所发现的那样,它返回一个异步迭代器。n.b.你不需要重复等待:
// instead of
for await (const inputFile of await ipfs.add({ path: 'randompath.txt', content: file })) {
// do:
for await (const inputFile of ipfs.add({ path: 'randompath.txt', content: file })) 它可以工作,但在Safari -崩溃中仍然存在问题。
Unhandled Rejection (TypeError): null is not an object (evaluating 'ipfs.add')

https://stackoverflow.com/questions/61086852
复制相似问题