使用JavaScript上传IPF上的对象

发布于 2025-02-07 01:50:05 字数 656 浏览 0 评论 0原文

我试图将对象上传到IPF中,但不支持错误

输入。预期的缓冲区| readableStream | pullstream | file | array< object>获得对象

这是我的JavaScript代码:

     let data = {
        name: bot,
        description: "",
        image: "https://ipfs.infura.io/ipfs/myimagehash",
      };

      const client = ipfsClient({
        host: "ipfs.infura.io",
        port: 5001,
        protocol: "https",
      });

      try {
        const added = await client.add(data);
        const url = `https://ipfs.infura.io/ipfs/${added[0].path}`;
        return url;
      } catch (error) {
        console.log("Error uploading file: ", error);
      }

I tried to upload an object into IPFS but there was an error

Input not supported. Expected Buffer|ReadableStream|PullStream|File|Array<Object> got object

this is my javascript code :

     let data = {
        name: bot,
        description: "",
        image: "https://ipfs.infura.io/ipfs/myimagehash",
      };

      const client = ipfsClient({
        host: "ipfs.infura.io",
        port: 5001,
        protocol: "https",
      });

      try {
        const added = await client.add(data);
        const url = `https://ipfs.infura.io/ipfs/${added[0].path}`;
        return url;
      } catch (error) {
        console.log("Error uploading file: ", error);
      }

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

灼疼热情 2025-02-14 01:50:05

好的,我以这种方式解决了这个问题:

let buffer = Buffer.from(JSON.stringify(this.form));
const added = await client.add(buffer);

ok I solved this problem this way:

let buffer = Buffer.from(JSON.stringify(this.form));
const added = await client.add(buffer);
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文