Deck API attachment upload from NODEJS

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
242254316-f8b25512-0b16-4c1e-afd0-f8783b8478761

So why i can upload this to Deck over API?

Hi @toniojstersek , I’m facing the same issue . Did you have success uploading the attachment? can you share how to do it ?

Finally , I found the way to attach from node red using the API , here an example:

https://nextcloud_host/index.php/apps/deck/api/v1.1/boards/{}/stacks/{}/cards/{}/attachments?type=file ( URL field of http request node ,… remember to fill the boards, stacks and cards )

Example function to inject in the http request node :

var filename = “test.png” // just an example
const data = msg.payload // Buffered .png file from http://url/test.png

msg.payload = {
“file”: {
“value”: data,
“options”: {
“filename”: filename
}
}
}
msg.headers = {

"Content-Type": "multipart/form-data"

}

return msg;

I apologize for the late reply. I’m glad you found a solution. jsz, I solved the problem at that time by making an interface using the Python API