How to use FormData object in requestConfluence function?

I have a Forge app that calls an API that returns the contents of a PDF file and I want to then attach those contents as a PDF file. To do this, I need to use FormData to create the body, but I’m trying the following:

const formData  = new FormData();

  formData.append("File-Name", "test-file");
  formData.append("Content-Type", "application/"pdf);
  formData.append("File", byteContent, "/C:/MyFolder/test-file.pdf");

  const response = await api.asApp().requestConfluence(route`/wiki/rest/api/content/${contentId}/child/attachment`, {

    method:  'PUT',

    headers: {

      'Accept': 'application/json',

      'Content-Type': 'multipart/form-data'

    },

    body: formData

  });

But I’m getting the following error:
“There was an error invoking the function - function () { [native code] } could not be cloned.”

If I use JSON.stringify like this: “body: JSON.stringify(formData)”, the call goes through without error in Forge, but of course I get an error code from the API because I need to implement formData and JSON.stringify only stringifies the object, it’s not the correct format like that.

Is there a way to implement FormData in requestConfluence correctly or will that only work if I make a custom fetch call to the API and provide the bearer token, etc.?

3 Likes

Have you resolved this problem?

1 Like

Same issue here