Skip to content

Instantly share code, notes, and snippets.

@polluterofminds
Created November 11, 2021 19:16
Show Gist options
  • Save polluterofminds/218b913de7094d64df5f6cf6acd7c4a4 to your computer and use it in GitHub Desktop.
Save polluterofminds/218b913de7094d64df5f6cf6acd7c4a4 to your computer and use it in GitHub Desktop.
Base64 Without File System
const { Readable } = require("stream");
const FormData = require("form-data");
const axios = require("axios");
(async () => {
try {
const base64 = "BASE64 FILE STRING;
const imgBuffer = Buffer.from(base64, "base64");
const stream = Readable.from(imgBuffer);
const data = new FormData();
data.append('file', stream, {
filepath: 'FILENAME.png'
})
const res = await axios.post("https://api.pinata.cloud/pinning/pinFileToIPFS", data, {
maxBodyLength: "Infinity",
headers: {
'Content-Type': `multipart/form-data; boundary=${data._boundary}`,
pinata_api_key: pinataApiKey,
pinata_secret_api_key: pinataSecretApiKey
}
});
console.log(res.data);
} catch (error) {
console.log(error);
}
})();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment