Created
November 10, 2021 20:30
-
-
Save polluterofminds/361611fcb489309e250901acc4cace9f to your computer and use it in GitHub Desktop.
Pinata SDK With base64
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const pinataSDK = require("@pinata/sdk"); | |
const pinata = pinataSDK( | |
"Pinata API Key", | |
"Pinata API Secret" | |
); | |
const { fs, vol } = require("memfs"); | |
(async () => { | |
try { | |
const base64 = "base64 file string"; | |
const buf = Buffer.from(base64, "base64"); | |
memfs.writeFileSync("File Name", buf); | |
const read = vol.createReadStream("File Name"); | |
const res = await pinata.pinFileToIPFS(read); | |
console.log(res); | |
} catch (error) { | |
console.log(error); | |
} | |
})(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment