Hi,
i trying to parsing email and get all attachment. I succesfuly create first part so i get all attachment and save it to local disk, Now i need to upload this file to Deck over API. I trying with next code but i get some error back… Does someone know what is this error?
.
.
.
mail.attachments.forEach(function (arrayItem) {fs.writeFile(arrayItem.filename, arrayItem.content, (err) => { if (err) throw err; });
console.log(‘File Buffer:’)
console.log(arrayItem.content) // content of file <Buffer 25 50 44 46…
console.log(‘-----------------------------’)const url = ‘https://site.com/apps/deck/api/v1.1/boards/4/stacks/11/cards/27/attachments’;
const options = {
method: ‘POST’,
headers : {
‘Content-Type’: ‘application/x-www-form-urlencoded’,
‘Authorization’: 'Basic ’ + Buffer.from(‘username:password’).toString(‘base64’),
}
};
const data = “type=file&file=” + arrayItem.content; // content of file <Buffer 25 50 44 46…let result = ‘’;
const req = https.request(url, options, (res) => {
console.log(res.statusCode);res.setEncoding('utf8'); res.on('data', (chunk) => { result += chunk; }); res.on('end', () => { console.log(result); });
});
req.on(‘error’, (e) => {
console.error(e);
});req.write(data);
req.end();
.
.
.
As you can see i gett error 500.
with fs.WriteFile i succesfuly create this physical file to disk from Buffer
So why i can upload this to Deck over API?