Good morning every one,
I’m try to attach a blob object to and issue via the jira cloud rest api.
Unfortunately I just receive a 415 status code. I think my issue is similar to this one Nestjs call rest attachments api not working, but I cannot make it work.
Here’s my code
const dataURLB64 = canvasRef.current.toDataURL()
const form = new FormData();
const file = DataURIToBlob(dataURLB64)
form.append('file',file, 'img.png')
const res = await sendToBackground({
name: "createJiraTicket",
body: {
issueKey: issueKey,
form: file
}
})
}
function DataURIToBlob(dataURI: string) {
const splitDataURI = dataURI.split(',')
const byteString = splitDataURI[0].indexOf('base64') >= 0 ? atob(splitDataURI[1]) : decodeURI(splitDataURI[1])
const mimeString = splitDataURI[0].split(':')[1].split(';')[0]
const ia = new Uint8Array(byteString.length)
for (let i = 0; i < byteString.length; i++)
ia[i] = byteString.charCodeAt(i)
return new Blob([ia], { type: mimeString })
}
an then my service worker does the fetch
const fetchRes = await fetch(`${process.env.PLASMO_PUBLIC_JIRA_API}/issue/${req.body.issueKey}/attachments`, {
method: 'POST',
body: req.body.form,
headers: {
'Authorization': `Basic ${Buffer.from(
`${process.env.PLASMO_PUBLIC_JIRA_USERNAME}:${process.env.PLASMO_PUBLIC_JIRA_API_TOKEN}`
).toString('base64')}`,
'Accept': 'application/json',
'X-Atlassian-Token': 'no-check'
}
})
console.log(fetchRes)