Jira Cloud API v3 Attachment Bug: How to Properly Handle Image Transfers?

I have an app that includes a feature to copy issues, created using Atlassian’s Cloud API v3. However, I’m encountering a bug with the API: when copying an issue that has an image in the description field, I need the media ID to save the attachment. Even though the media ID is valid and the original issue displays the image correctly, the API throws an error saying it can’t find the media ID when creating the copied issue.
I reached out to Atlassian, and they suggested switching to API v2. I’m currently implementing this by changing the create API to v2 and handling attachments by downloading the image from the content URL of original issue, converting it to a blob using AP.request, and then creating a file to add the attachment. While I’ve managed to upload the image, it only displays as a broken image.
Here is the code to download and upload the attachment:

                     AP.request({
                        url: att.content,
                        type: 'GET',
                        headers: {
                            "Accept": "*/*",
                            'Access-Control-Expose-Headers': 'ETag, Link',
                        },
                        success: (res) => {
                            const blob = new Blob([res], { type: att.mimeType })
                            const file = new File([blob], att.filename, { type: att.mimeType })
                            
                            AP.request({
                                url: `/rest/api/3/issue/${issueKey[0]}/attachments`,
                                type: 'POST',
                                data: { file: file },
                                binaryAttachment: true,
                                contentType: "multipart/form-data",
                                headers: {
                                    'Access-Control-Expose-Headers': 'ETag, Link',
                                    "Accept": "application/json",
                                    "X-Atlassian-Token": "no-check",
                                },
                                success: (res) => {
                                },
                                error: function (xhr, statusText, errorThrown) {
                                },
                            });
                        },
                        error: (err) => {
                        }
                    })

Is my approach correct? Is there a better way to solve this issue?

1 Like

I’m experiencing the same issue. Remind me if you find a solution.