js-IPFS / vue.js上传错误-对象不是异步可迭代的

问题描述

我一直在开发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

相关问答

Selenium Web驱动程序和Java。元素在(x,y)点处不可单击。其...
Python-如何使用点“。” 访问字典成员?
Java 字符串是不可变的。到底是什么意思?
Java中的“ final”关键字如何工作?(我仍然可以修改对象。...
“loop:”在Java代码中。这是什么,为什么要编译?
java.lang.ClassNotFoundException:sun.jdbc.odbc.JdbcOdbc...