Despite receiving a 200 OK, the file isn’t attached to my JIRA issue. I convert base64 data into a stream and submit multipart form data. What might be wrong?
const dataBuffer = Buffer.from(req.encodedData, 'base64');
const { Readable } = require('stream');
const streamData = new Readable();
streamData._read = () => {};
streamData.push(dataBuffer);
streamData.push(null);
const multipartPayload = {
document: {
stream: streamData,
fileName: req.fileLabel,
contentType: req.fileType
}
};
const options = {
url: 'https://company.atlassian.net/rest/api/2/issue/' + req.issueKey + '/attachments',
method: 'POST',
headers: {
'Content-Type': 'multipart/form-data',
'Authorization': 'Basic ' + Buffer.from(config.jira.user + ':' + config.jira.pass).toString('base64'),
'X-Atlassian-Token': 'nocheck'
},
formData: multipartPayload
};
require('request')(options, (err, res, body) => {
if (err) return console.error('Error:', err);
console.log('Status:', res.statusCode);
});
Based on similar situations I’ve encountered, the issue likely stems from how the multipart form data is being handled. While a 200 status suggests the request went through, the server may not be parsing the file stream properly. My experience indicated that directly using Readable streams sometimes creates problems with the boundary data used by multipart requests. Another potential problem could be with the content type or the way the encoded data is converted from base64. Consider verifying that the file stream is added to the form correctly and that the request library isn’t interfering with the multipart boundaries.
hey, try not manually setting the content-type header - let the request lib handle it. sometimes the api expects a different field name than ‘document’, maybe ‘file’ instead. check that and your file size limits too, could be causing the attachment not to register
My experience with similar issues led me to reexamine how the multipart form is being constructed. I encountered an issue where relying on the in-built mechanisms of certain libraries caused the file stream to be interpreted incorrectly by JIRA’s API. Switching to a more dedicated multipart form builder helped in ensuring that stream metadata, such as file size and boundaries, was properly attached. I also recommend looking into how the stream is being terminated, as minor discrepancies can result in a seemingly successful 200 response while the file is not actually attached. Consider verifying these low-level details during your debugging process.