dropzone
Unanswered
New Zealand Heading Dog posted this in #help-forum
New Zealand Heading DogOP
i am trying to upload a file to pinata using dropzone and pinata SDK
the function which i am using from SDK needs a readableStream but i don't know how can i make a readableStream from the file i got with dropzone
In there example , Pinata have this code
if i use file.filepath it is undefined in my case and thus gives me error
the function which i am using from SDK needs a readableStream but i don't know how can i make a readableStream from the file i got with dropzone
In there example , Pinata have this code
const axios = require('axios')
const FormData = require('form-data')
const fs = require('fs')
const JWT = 'Bearer PASTE_YOUR_PINATA_JWT'
const pinFileToIPFS = async () => {
const formData = new FormData();
const src = "path/to/file.png";
const file = fs.createReadStream(src)
formData.append('file', file)
const pinataMetadata = JSON.stringify({
name: 'File name',
});
formData.append('pinataMetadata', pinataMetadata);
const pinataOptions = JSON.stringify({
cidVersion: 0,
})
formData.append('pinataOptions', pinataOptions);
try{
const res = await axios.post("https://api.pinata.cloud/pinning/pinFileToIPFS", formData, {
maxBodyLength: "Infinity",
headers: {
'Content-Type': `multipart/form-data; boundary=${formData._boundary}`,
Authorization: JWT
}
});
console.log(res.data);
} catch (error) {
console.log(error);
}
}if i use file.filepath it is undefined in my case and thus gives me error