问题描述
我一直在开发js-ipfs(0.49.0),并且工作正常,但是我开始遇到一些问题,无论如何,我终于再次回到代码中,并且连接正常,但是当我尝试上传时出现新错误
对象不可异步迭代
我不确定这在代码中意味着什么或如何解决,很多示例是为了响应而不是目的
任何有用的指针。
methods: {
async getIpfsNodeInfo() {
try {
// Await for ipfs node instance.
node = await ipfs
// console.log(node)
// Call ipfs `id` method.
// Returns the identity of the Peer.
const { agentVersion,id } = await node.id()
this.agentVersion = agentVersion
this.id = id
// Set successful status text.
this.status = 'Connected to IPFS ?'
} catch (err) {
// Set error status text.
this.status = `Error: ${err}`
}
},onFileSelected(event) {
this.selectedFile = event.target.files[0]
this.saveIPFS()
},async saveIPFS() {
try {
for await (const result of node.add(this.selectedFile)) {
this.fileContents = result
this.getIPFS()
}
} catch (err) {
// Set error status text.
this.status = `Error: ${err}`
}
},
解决方法
ipfs.add
返回一个对象,因为ipfs@0.48.0
-您需要更改:
async saveIPFS() {
try {
for await (const result of node.add(this.selectedFile)) {
this.fileContents = result
this.getIPFS()
}
} catch (err) {
// Set error status text.
this.status = `Error: ${err}`
}
},
收件人:
async saveIPFS() {
try {
this.fileContents = await node.add(this.selectedFile)
this.getIPFS()
} catch (err) {
// Set error status text.
this.status = `Error: ${err}`
}
},
有关更多信息,请参见博客文章:https://blog.ipfs.io/2020-07-20-js-ipfs-0-48/#ipfs-add