duanbi6522
duanbi6522
2017-08-09 08:07
浏览 141
已采纳

尝试将文件发送到IPFS时出现“找不到命令”

I'm want to use IPFS in my project, then, I'm studying about Go IPFS API. Then, I wrote this very simple code:

package main

import (
    "fmt"
    "bytes"
    sh "github.com/ipfs/go-ipfs-api"
)

func main() {
    shell := sh.NewShell("https://ipfs.io")

    bufferExample := bytes.NewBufferString("Hello IPFS Shell tests")
    mhash, err := shell.AddNoPin(bufferExample)

    if err != nil {
        panic(err) // ends where
    }

    fmt.Println(mhash)
}

But I receive the error panic: add: command not found, and I don't understand why. I already have IPFS in my computer (I can run the deamon, for example). I also installed the Go IPFS library with development dependencies.

How to fix it?

图片转代码服务由CSDN问答提供 功能建议

我想在我的项目中使用IPFS,然后,我正在研究Go IPFS API。 然后 ,我写了这个非常简单的代码:

  package main 
 
import(
“ fmt” 
“ bytes” 
 sh“ github.com/ipfs/go  -ipfs-api“ 
)
 
func main(){
 shell:= sh.NewShell(” https://ipfs.io“)
 
 bufferExample:= bytes.NewBufferString(” Hello IPFS Shell 测试”)
 mhash,错误:= shell.AddNoPin(bufferExample)
 
,如果错误!= nil {
 panic(err)//结束于
} 
 
 fmt.Println(mhash)\  n} 
   
 
 

但是我收到错误 panic:add:not found command ,而且我不明白为什么。 我的计算机中已经有IPFS(例如,可以运行守护进程)。 我还安装了具有开发依赖关系的Go IPFS库。

如何修复它?

  • 点赞
  • 写回答
  • 关注问题
  • 收藏
  • 邀请回答

2条回答 默认 最新

  • duandie0884
    duandie0884 2017-08-09 14:25
    已采纳

    User Magik6k answered my question in another forum:

    You can't use the public IPFS gateway to add content. For this you need locally running daemon and pass it's API endpoint to NewShell (localhost:5001 by default).

    Public gateways(ipfs.io, localhost:8080) only support a limited API subset, see https://github.com/ipfs/go-ipfs/blob/master/core/commands/root.go#L1412 for what is available

    点赞 评论
  • dongqia3502
    dongqia3502 2017-08-09 08:27

    The error has nothing to do with the various paths. The program is running and it's panicking because you have asked it to in case of an error:

    mhash, err := shell.AddNoPin(bufferExample)
    if err != nil {
        panic(err) // ends where
    }
    

    The error add: command not found is a result of your system not being able to locate the add command (error is an http 404).

    Have you installed IPFS command on your system? If not, try after doing that.

    点赞 评论

相关推荐