Send blob object with jira cloud rest api

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(
            'Accept': 'application/json',
            'X-Atlassian-Token': 'no-check'

Welcome to the Atlassian developer community @polipetto,

The short answer is the attachments endpoints don’t accept JSON. As the documentation explains:

Attachments are posted as multipart/form-data (RFC 1867).
Note that:

  • The request must have a X-Atlassian-Token: no-check header, if not it is blocked. See Special headers for more information.
  • The name of the multipart/form-data parameter that contains the attachments must be file.

So you’ll need to structure your request in the service worker differently. Both the body and the Accept header need to reflect structuring as multipart form data.