0

我正在使用 ipfs - api 进行开发,我遇到了以下错误,将图像文件添加到 ipfs 节点无法正常工作。查看错误的详细信息,似乎协议在 request.js 中的 if (protocol.indexOf ('https') === 0) { 中被视为未定义。

这是错误描述

Uncaught (in promise) TypeError: Cannot read property 'indexOf' of undefined
    at webpackJsonp../node_modules/ipfs-api/src/utils/request.js.module.exports (request.js:7)
    at requestAPI (send-request.js:165)
    at send (send-request.js:196)
    at send-files-stream.js:99
    at Function.promisify (add.js:41)
    at index.js:32
    at Object.add (add.js:60)
    at VueComponent._callee$ (HaikuCompose.vue?0664:118)
    at tryCatch (runtime.js:62)
    at Generator.invoke [as _invoke] (runtime.js:296)

这是我写的代码

import IPFS from "ipfs-api"
const ipfsConf = { host: process.env.IPFSHOST, port: process.env.IPFSPORT, protocol: process.env.IPFSPROTCOL }
const ipfs = new IPFS(ipfsConf)

export default {
  name: 'ipfstest',
  data() {
    return {
      file:null,
      buffer:null,
      ipfsHash:null,
    }
  },
  methods: {
    async addipfs() {
      await ipfs.add(this.buffer, (err, ipfsHash) => {
        console.log(err,ipfsHash);
        this.ipfsHash = ipfsHash[0].hash;
      }) 
    },
4

1 回答 1

0

从模块源中,request.js 文件的第 7 行indexOf用于存储协议的变量,在您的情况下。undefined

从你的代码中,我想我可以安全地假设你的环境变量process.env.IPFSPROTCOL是未定义的。

TL:DR : 我想你想写IPFSPROTOCOL而不是IPFSPROTCOL

于 2018-05-17T08:17:09.783 回答