Skip to content

Instantly share code, notes, and snippets.

@polluterofminds
Created November 9, 2021 22:32
Show Gist options
  • Save polluterofminds/368ee38629fad02e979a721f1e8883bb to your computer and use it in GitHub Desktop.
Save polluterofminds/368ee38629fad02e979a721f1e8883bb to your computer and use it in GitHub Desktop.
Pinata Large Folder Uploads
const fs = require("fs");
const FormData = require("form-data");
const rfs = require("recursive-fs");
const basePathConverter = require("base-path-converter");
const got = require('got');
const pinDirectoryToPinata = async () => {
const url = `https://api.pinata.cloud/pinning/pinFileToIPFS`;
const src = "RELATIVE PATH TO DIRECTORY TO UPLOAD";
var status = 0;
try {
const { dirs, files } = await rfs.read(src);
let data = new FormData();
for (const file of files) {
data.append(`file`, fs.createReadStream(file), {
filepath: basePathConverter(src, file),
});
}
const response = await got(url, {
method: 'POST',
headers: {
"Content-Type": `multipart/form-data; boundary=${data._boundary}`,
"Authorization": "Bearer JWT FROM PINATA API KEYS"
},
body: data
})
.on('uploadProgress', progress => {
console.log(progress);
});
console.log(JSON.parse(response.body));
} catch (error) {
console.log(error);
}
};
@xpluscal
Copy link

@polluterofminds the pinata api returns "BAD REQUEST".
currently trying to find a solution that would work with this hack: PinataCloud/Pinata-SDK#28 (comment)

@polluterofminds
Copy link
Author

@xpluscal do you mean the API returns that response with the above code? Or do you mean you're getting that response when using the SDK?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment