const fetch = require('node-fetch');
const FormData = require('form-data');
const fs = require('fs');
const filePath = file.documentPath;
const form = new FormData();
const stats = fs.statSync(filePath);
const fileSizeInBytes = stats.size;
const fileStream = fs.createReadStream(filePath);
form.append(file.documentFileName, fileStream, {knownLength: fileSizeInBytes});
result = await fetch(`${host}/rest/api/3/issue/${issueKey}/attachments`, {
method: 'POST',
body:form,
headers: {
'Authorization': `Basic ${Buffer.from(
'Email : API token'
).toString('base64')}`,
'Accept': 'application/json',
'X-Atlassian-Token': 'no-check',
'Content-Type': 'application/json'
}
}).then((response:any) => {
console.log("response",response)
response.json()}).then((jsonResponse:any) => {
console.log("jsonResponse", jsonResponse)
return jsonResponse
});
This is the code for my node.js
Without the 'Content-Type': 'application/json', I am receiving
status: 400,
statusText: 'Bad Request'
After adding in the 'Content-Type': 'application/json', I am receiving
status: 415,
statusText: 'Unsupported Media Type'