outlookoffice365office-jsoutlook-web-addinsoutlook-web-app

Why do I get error when trying to add file attachments?


I am trying to use the method addFileAttachmentAsync() in office.js library.

This is the signature of the method I am using:

item.addFileAttachmentAsync(uploadLink, fileJson.name, { asyncContext: null }, function (asyncResult) { });

uploadLink is a string and here is an example of a file I'm trying to upload: https://xdr.purequad.com:6443/files/1b783908-a259-4839-93e2-18fe3248b943_moto.pdf.xdr

The file above is about ~3MB, but when I use a file under 1MB everything works perfectly.

Afterwards it throws this Exception :

Line: 9 Error: Unable to get property 'isInstanceOfType' of undefined or null reference

Also I have to mention this behavior happens only in IE11, while Google Chrome does not throw any exception at all and still does not work.

EDIT: The function was being interrupted before it ended properly! Check my comment.


Solution

  • I have solved the issue myself. When using addFileAttachmentAsync() because it's an async call one should never interrupt the task-pane with Office.context.ui.closeContainer() which was my case. Otherwise it will generate unexpected behavior.