无法使用 Pinata pinFileToIPFS() 将可读流上传到 Nuxt.js 应用程序上的 IPFS

发布于 2025-01-17 01:10:59 字数 1725 浏览 1 评论 0原文

我正在开发一个项目(使用 Nuxt.js),我需要将图像上传到 IPFS 上。

我尝试将 static 目录中的图像转换为 readstream ,但它不起作用。

这是我的代码:

<script>
import '@pinata/sdk'

export default {
  methods: {
    async create() {
      const pinataSDK = require('@pinata/sdk')
      const pinata = pinataSDK(
        'MY_KEY',
        'MY_SECRET_KEY'
      )
      const file = await fetch('~/static/test.svg').then(
        (response) => response.body
      )
      const readableStreamForFile = await fetch(
        '~/static/recording-button.svg'
      ).then((response) => response.body)
      console.log(readableStreamForFile)

      pinata
        .pinFileToIPFS(readableStreamForFile)
        .then((result) => {
          // handle results here
          console.log(result)
        })
        .catch((err) => {
          // handle error here
          console.log(err)
        })
    },
  },
}
</script>

这是错误代码:

TypeError: source.on is not a function
    at Function../node_modules/delayed-stream/lib/delayed_stream.js.DelayedStream.create (pinata-sdk.js?a4ab:14807:1)
    at FormData../node_modules/combined-stream/lib/combined_stream.js.CombinedStream.append (pinata-sdk.js?a4ab:3493:1)
    at FormData../node_modules/form-data/lib/form_data.js.FormData.append (pinata-sdk.js?a4ab:15501:1)
    at eval (pinata-sdk.js?a4ab:22908:1)
    at new Promise (<anonymous>)
    at pinFileToIPFS (pinata-sdk.js?a4ab:22906:1)
    at Object.client.pinFileToIPFS (pinata-sdk.js?a4ab:23783:1)
    at _callee2$ (new.vue?a8eb:144:1)
    at tryCatch (runtime.js?96cf:63:1)
    at Generator.invoke [as _invoke] (runtime.js?96cf:294:1)

此错误是否表示图像不是可读流? 我仍然是 web3 和区块链的新手,所以请帮助!

I am working on a project (using Nuxt.js), I need to upload the image on IPFS.

I tried to convert the image in static directory to readablestream , but it didn't work.

Here is my code:

<script>
import '@pinata/sdk'

export default {
  methods: {
    async create() {
      const pinataSDK = require('@pinata/sdk')
      const pinata = pinataSDK(
        'MY_KEY',
        'MY_SECRET_KEY'
      )
      const file = await fetch('~/static/test.svg').then(
        (response) => response.body
      )
      const readableStreamForFile = await fetch(
        '~/static/recording-button.svg'
      ).then((response) => response.body)
      console.log(readableStreamForFile)

      pinata
        .pinFileToIPFS(readableStreamForFile)
        .then((result) => {
          // handle results here
          console.log(result)
        })
        .catch((err) => {
          // handle error here
          console.log(err)
        })
    },
  },
}
</script>

Here is error code:

TypeError: source.on is not a function
    at Function../node_modules/delayed-stream/lib/delayed_stream.js.DelayedStream.create (pinata-sdk.js?a4ab:14807:1)
    at FormData../node_modules/combined-stream/lib/combined_stream.js.CombinedStream.append (pinata-sdk.js?a4ab:3493:1)
    at FormData../node_modules/form-data/lib/form_data.js.FormData.append (pinata-sdk.js?a4ab:15501:1)
    at eval (pinata-sdk.js?a4ab:22908:1)
    at new Promise (<anonymous>)
    at pinFileToIPFS (pinata-sdk.js?a4ab:22906:1)
    at Object.client.pinFileToIPFS (pinata-sdk.js?a4ab:23783:1)
    at _callee2$ (new.vue?a8eb:144:1)
    at tryCatch (runtime.js?96cf:63:1)
    at Generator.invoke [as _invoke] (runtime.js?96cf:294:1)

Is this error that the image is not readable stream?
I am still a newbie to web3 and blockchains so please help!

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

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

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。
列表为空,暂无数据
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文