简体   繁体   English

当我尝试用我的 nodejs Dapp 添加 ipfs 文件时出错

[英]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.

相关问题 当我尝试运行带有jQuery的文件时出现nodejs错误 - nodejs error when i try to run a file with jquery in it 当我尝试连接到我的数据库 nodejs 时,我收到一个未知的数据库错误 - Im getting a unknown database error when i try to connect to my database nodejs 当我尝试使用 nodejs 创建一个新文件时出现错误 - When i try to create a new file using nodejs i get an error 当我尝试将文件添加到我的存储库时,Git 抛出一个 readlink 错误 - Git is throwing a readlink error when I try and add files to my repo 更新 NodeJs -> 添加 Android 时出错 - Update NodeJs -> Error when i add Android 如何使用Nodejs通过ipfs下载文件? - How download file via ipfs using Nodejs? 在 NodeJS 中将上传的文件保存到 Pinata IPFS - Saving uploaded file to Pinata IPFS in NodeJS 尝试要求我的javascript文件时找不到模块“ models / PermissionModel”错误 - Cannot find module 'models/PermissionModel' error when I try to require my javascript file 我尝试在我的 mocha nodejs 测试中上传文件,但我得到了 [Object null prototype] { file: {... }} - i try to upload file in my mocha nodejs test but i got [Object null prototype] { file: { ... }} 如何使用 js (ipfs-http-client) 将我的 IPFS 返回转换为 original.midi 或 .png 文件? - How do I convert my IPFS return into the original .midi or .png file using js (ipfs-http-client)?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM