blockfrost / blockfrost-js

Node.js SDK for the Blockfrost.io API.
https://blockfrost.io
Apache License 2.0
105 stars 24 forks source link

Upload Image To IPFS #281

Closed santiagoziel closed 1 year ago

santiagoziel commented 1 year ago

deno 1.35.3 (release, x86_64-pc-windows-msvc) v8 11.6.189.12 typescript 5.1.6 Windows 10

Trying to follow the upload file exmple, uploading an image gets stuck, no error showing up

import { BlockFrostIPFS } from "npm:@blockfrost/blockfrost-js"

const ipfs = new BlockFrostIPFS({ projectId: "ipfsaaaaaaaaaaaaaaaaaaaaaaa" })
const savedHashPath = "logo-ipfs.json"
console.log(`adding image`)
const addResponse = await ipfs.add("image_name.png")
console.log(`pinning image`)
const pinResponse = await ipfs.pin(addResponse.ipfs_hash)
writeJson(savedHashPath, { ipfsHash: pinResponse.ipfs_hash })

"image_name.png" is a file contianing a 111KB image on the same folder as the script.

I have also tried the full Path of the file but both display the same behaviour.

"adding image" log does display but then nothing.

no request is being shown on my Blockfrost dashboard.

NOTE: This is more than likely missuse form my part and not an issue of the SDK but the web page instructed me to open an issue here for help wiht using the SDK.

santiagoziel commented 1 year ago

I have tried this exact code but on a NodeJs env and there it worked as expected

slowbackspace commented 1 year ago

Hi @santiagoziel This is an SDK for Node.js. We don't support Deno. I don't have an experience with Deno, but I assume the issue is that IPFS's add method needs to execute native nodejs fs (since there is not much else).

If you are able to use other methods to query the blockchain, such as BlockfrostAPI.blocksLatest() (see example in readme), we could update the add method so it accepts stream/binary data as a parameter. Then you could handle fs read on your own and just pass binary data to the SDK. Let me know if that would work for you.

Just curious, where did you find tutorial for Deno that uses Blockfrost SDK?

santiagoziel commented 1 year ago

Hi @slowbackspace!

yeah passing the binary data woudl work, but for now using the SDK over on Node has been sufficient for me.

I did not follow any tutorial other than the Blockfrost documentation, i just used Deno on my own, I had used the SDK on Deno before to query the Blockchain without issues.