[Vuejs]-Using js-ipfs in vue to upload and display images

0👍

This worked

const ipfs = VueIpfs.create()


//  The below code should create an IPFS node to add files to
export default {
  name: 'IpfsInfo',
  data: function () {
    return {
      status: 'Connecting to IPFS...',
      id: '',
      agentVersion: '',
    }
  },
  mounted: function () {
    console.log(VueIpfs)
    this.getIpfsNodeInfo()
  },
  methods: {
    selectedFile(event) {
      this.file = event.target.files[0]
//TODO: Something like the below
      // console.log(this.file)
      //  ipfs.add(this.file)
    },
    async getIpfsNodeInfo() {
      try {
        // Await for ipfs node instance.
        const node = await ipfs
        //console.log(ipfs)
        // 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}`
      }
    },
  },
}```

Leave a comment