I am trying to call /attachments endpoint to post new attachment to the issue. However, I am keep getting errors. First error that I am getting is statusText: ‘Unsupported Media Type’,
then I’ve also tried adding ‘Content-type’ header but it then gives me error 500.
app.post("/attachment", multer().single("file"), async (req, res) => {
console.log(req.file);
fetch("http://localhost:8080/rest/api/latest/issue/DP-2/attachments", {
method: "POST",
body: req.file,
headers: {
Authorization: "Basic xxx",
"X-Atlassian-Token": "no-check",
},
})
.then((res) => console.log(res))
.then((result) => res.json(result))
.catch((err) => console.log(err));
});
This is called from my node.js server to avoid cors issue. To make it more clear here is what is passed to the req.file:
{
fieldname: 'file',
originalname: 'file.txt',
encoding: '7bit',
mimetype: 'text/plain',
buffer: <Buffer 74 65 73 74 73 65 74 65 73 74 73 74 65 74>,
size: 14
}
It works fine with the Postman, but not in browser. Appreciate any help.