尝试将文件发送到IPFS时出现“命令未找到”
问题描述:
我想在我的项目中使用IPFS,然后我在研究Go IPFS API。 于是,我写了这个非常简单的代码:尝试将文件发送到IPFS时出现“命令未找到”
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)
}
但我收到错误panic: add: command not found
,我不明白为什么。我的电脑中已经有IPFS(例如,我可以运行deamon)。我还安装了带有开发依赖关系的Go IPFS库。
如何解决?
答
用户Magik6k回答我的问题在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
是的,我已经安装了IPFS命令。例如,我可以运行守护进程。 – Macabeus