[英]Error when I try to add ipfs file with my nodejs Dapp
I am trying to create a Dapp with nodejs that allow me to upload a file to IPFS running in local, but I'm haveing some troubles.我正在尝试使用 nodejs 创建一个 Dapp,它允许我将文件上传到在本地运行的 IPFS,但我遇到了一些麻烦。
I've tried the next我试过下一个
submit_change: document.getElementById('upload_form').addEventListener('submit', async function(event) {
event.preventDefault();
const ipfs = create({host: "127.0.0.1", port: 8081, protocol: "http"})
await ipfs.add("Hello world!", (error, res) => {
console.log(res)
if(error){
console.log(err)
}
})
}),
But I get this:但我明白了:
POST http://127.0.0.1:8081/api/v0/add?stream-channels=true&progress=false 404 (Not Found)
fetch @ http.js:147
Client.fetch @ core.js:148
post @ http.js:189
addAll @ add-all.js:23
await in addAll (async)
last @ index.js:13
add @ add.js:25
eval @ index.js:98
core.js:67 Uncaught (in promise) HTTPError: 404 page not found
at Object.errorHandler [as handleError] (core.js:67:15)
at async Client.fetch (http.js:155:9)
at async addAll (add-all.js:23:17)
at async last (index.js:13:20)
at async HTMLFormElement.eval (index.js:98:5)
errorHandler @ core.js:67
In theory, IPFS is running in the port 8081 and the app in the 8080. If I add something from my linux terminal with the comand "ipfs add", it works fine and I can se what I've uploaded with the url http://127.0.0.1:8081/ipfs/hash .理论上,IPFS 在端口 8081 中运行,应用程序在 8080 中运行。如果我使用命令“ipfs add”从我的 linux 终端添加一些东西,它工作正常,我可以看到我用 url http 上传的内容: //127.0.0.1:8081/ipfs/哈希。
What am I doing wrong in my Dapp我在我的 Dapp 中做错了什么
You can check out Moralis IPFS API which makes this process a lot easier!您可以查看 Moralis IPFS API,这让这个过程变得容易多了! Here you can find a guide on how to use it https://docs.moralis.io/web3-data-api/evm/how-to-upload-a-folder-to-ipfs .您可以在这里找到有关如何使用它的指南https://docs.moralis.io/web3-data-api/evm/how-to-upload-a-folder-to-ipfs 。
Let me know if you need any help!如果您需要任何帮助,请告诉我!
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.