I'm using the following code to add an attachment to a list item:
const context = new SP.ClientContext.get_current();
const attachments = context
.get_web()
.getFolderByServerRelativeUrl(
`Lists/${list}/Attachments/${itemId}`
);
const createInfo = new SP.FileCreationInformation();
const base64 = await toBase64(file);
createInfo.set_content(base64);
createInfo.set_url(file.name);
const files = attachments.get_files();
files.add(createInfo);
However, when uploading files larger than 2mb, the server throws an error.
So my question is: how to upload larger files using the Sharepoint JavaScript API?