How to add an attachment to issue in Forge?

Hi Community!
I’ve tried a lot to upload attachment to jira issue in my forge app.

My forge app recieves base64 encoded file from custom ui function.
Here’s example of my function:

const form = new FormData();
  form.append("file", "file")
  const response = await api.asUser().requestJira(route`/rest/api/2/issue/${issueId}/attachments`, {
    method: 'POST',
    body: form,
    headers: {
      'Accept': 'application/json',
      'X-Atlassian-Token': 'no-check',
    }
  });

After launching this part of code I get next error:

function () { [native code] } could not be cloned.
TypeError: function () { [native code] } could not be cloned.

I know that problem is here:
form.append("file", "file")
but I don’t know what’s wrong…
Also I’ve tried
form.append("file", Buffer.from("file", 'base64'))
And got the same error

1 Like

Hi @belokurbohdan
did you find a solution for the problem? I am asking because I got the same error when trying to add an attachment to a Jira issue via REST API.
According to the documentation here, this seems somehow possible with this code

// This sample uses Atlassian Forge and the `form-data` library.
 // https://developer.atlassian.com/platform/forge/
 // https://www.npmjs.com/package/form-data
 import api from "@forge/api";
 import FormData from "form-data";

 const form = new FormData();
 form.append('file', fileStream, {knownLength: fileSizeInBytes});

 const response = await api.asApp().requestJira('/rest/api/2/issue/{issueIdOrKey}/attachments', {
     method: 'POST',
     body: form,
     headers: {
         'Accept': 'application/json',
         'X-Atlassian-Token': 'no-check'
     }
 });

 console.log(`Response: ${response.status} ${response.statusText}`);
 console.log(await response.json());

Unfortunately, I wasn’t able to get the filestream of my file so far. All my attempts ended with the same error you mentioned.

function () { [native code] } could not be cloned.
TypeError: function () { [native code] } could not be cloned.
1 Like

Unfortunately, this issue hasn’t been resolved yet :expressionless:

From what I can tell, this is now captured in: [FRGE-635] - Ecosystem Jira

Please watch, comment, and vote there.

1 Like