无法使用 Pinata pinFileToIPFS() 将可读流上传到 Nuxt.js 应用程序上的 IPFS
我正在开发一个项目(使用 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 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论