Created
November 9, 2021 22:32
-
-
Save polluterofminds/368ee38629fad02e979a721f1e8883bb to your computer and use it in GitHub Desktop.
Pinata Large Folder Uploads
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 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 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
@polluterofminds the pinata api returns "BAD REQUEST".
currently trying to find a solution that would work with this hack: PinataCloud/Pinata-SDK#28 (comment)