Uploading an attachment crashes the entire page

I’ve been using the c[ode from the docs] (Request), the second example:


var fileToUpload = document.getElementById("fileInput").files[0];

AP.request({
  url: '/rest/api/content/123456/child/attachment',
  type: 'POST',
  contentType: 'multipart/form-data',
  data: {comment: 'example comment', file: fileToUpload},
  success: function(responseText){
    alert(responseText);
  }
});

However, when I run that code in my app to upload an attachment, the entire page crashes:

There is no error as the browser crashes before anything can happen. I can’t even see the API result. Sending the file from postman works. Is there a bug in AP.request?

Hi @PhilipFeldmann

How big is the filed you’re trying to upload?
And also, have you tried this on a different browser or a different site?

Best,
Gabriel

I found out that this is a bug that is actually 4 years old: [CONFCLOUD-61372] Attachment upload to custom content in Confluence not working in Chrome - Create and track feature requests for Atlassian products.

It happens in chrome across operating systems. There is a weird workaround mentioned in the comments, but because the exact snippet from the docs doesn’t work I still consider this a bug.