# Send blob object with jira cloud rest api

**URL:** <https://community.developer.atlassian.com/t/send-blob-object-with-jira-cloud-rest-api/76894>\
**Category:** Jira Cloud\
**Tags:** blob, image, attachment, jira-cloud\
**Created:** [February 4, 2024, 12:45am UTC](https://community.developer.atlassian.com/t/send-blob-object-with-jira-cloud-rest-api/76894 "2024-02-04T00:45:25Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![polipetto](https://avatars.discourse-cdn.com/v4/letter/p/b2d939/32.png) [@polipetto](https://community.developer.atlassian.com/u/polipetto)\
**Post date:** [February 4, 2024, 12:45am UTC](https://community.developer.atlassian.com/t/send-blob-object-with-jira-cloud-rest-api/76894/1 "2024-02-04T00:45:25Z")

</div>

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](https://community.developer.atlassian.com/t/nestjs-call-rest-attachments-api-not-working/58674), but I cannot make it work.  
Here’s my code

```auto
            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

```auto
    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)

```

---

<div class="post-metadata">

**Author:** ![ibuchanan](https://sea1.discourse-cdn.com/atlassiandeveloper/user_avatar/community.developer.atlassian.com/ibuchanan/32/35815_2.png) [@ibuchanan](https://community.developer.atlassian.com/u/ibuchanan)\
**Post date:** [February 4, 2024, 10:35am UTC](https://community.developer.atlassian.com/t/send-blob-object-with-jira-cloud-rest-api/76894/2 "2024-02-04T10:35:25Z")

</div>

Welcome to the Atlassian developer community @polipetto,

The short answer is the attachments endpoints don’t accept JSON. As [the documentation](https://developer.atlassian.com/cloud/jira/platform/rest/v3/api-group-issue-attachments/#api-rest-api-3-issue-issueidorkey-attachments-post) explains:

> Attachments are posted as multipart/form-data ([RFC 1867](https://www.ietf.org/rfc/rfc1867.txt)).  
> Note that:
> 
> - The request must have a `X-Atlassian-Token: no-check` header, if not it is blocked. See [Special headers](https://developer.atlassian.com/cloud/jira/platform/rest/v3/intro/#special-request-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.
