问题
I'm trying to get the content of an attachment from a mail item using the Office.context.mailbox.item.getAttachmentsAsync() API call from my add-in, however I'm running into some unexpected results...
In my add-in, I get a list of all the attachments in the mail item:
var listOfAttachments = item.attachments;
if (listOfAttachments.length > 0) {
for (i = 0; i < listOfAttachments.length; i++) {
_att = listOfAttachments[i];
console.log("Attachment name: " + _att.name);
console.log("Attachment type: " + _att.attachmentType);
console.log("Attachment content type: " + _att.contentType);
console.log("Attachment ID: " + _att.id);
console.log("string length: " + _att.id.length);
}
This works fine... However, I realised that the attachment ID, is longer than 100 characters (180 characters actually). And in the API reference of the getAttachmentContentAsync() function, the first parameter is the attachment ID, which the reference states: "The identifier of the attachment you want to get. The maximum length of the string is 100 characters."
So based on that, I think I have identified the problem. The issue now is, how to solve it. What attachment ID is this API expecting?
Thanks!
Update: This is the code that I'm using to retrieve the attachment content:
var options = { asyncContext: { type: _att.attachmentType } };
item.getAttachmentContentAsync(_att.id, options, function (result) {
if (result.status == Office.AsyncResultStatus.Succeeded) {
console.log("Call returned success!");
var AttachmentContent = result.value; // Get the attachment content
if (AttachmentContent.format == Office.MailboxEnums.AttachmentContentFormat.Base64) {
// handle file attachment
console.log("Base64 String: " + AttachmentContent.content);
}
else if (result.format == Office.MailboxEnums.AttachmentContentFormat.Eml) {
// handle item attachment
}
else {
// handle cloud attachment
}
} else {
var err = result.error;
console.log("Call failed: " + err.name + ": " + err.message);
}
});
The error that I'm getting is this: Unable to get property 'status' of undefined or null reference
For purpose of troubleshooting, I printed out the attachment id: AAMkADU4OTU2Mjg4LThiNzktNDY0Yi1hZmE4LWFmMjAzZjczYjIxOQBGAAAAAADiRE+1naePQ7MPCJEcJqgqBwCgpNXsitDwTY/mc0w2Y/zOAAAAAAEMAACgpNXsitDwTY/mc0w2Y/zOAAARXFqBAAABEgAQAN0M5JhRvPxIoP5KYNYRk54=
I read from a few pages that different API expects slightly different format of the attachment id. So I'm not sure if this is the source of the issue...
回答1:
The getAttachmentContent API is not yet implemented for OWA. For the null result object - This is a known issue. It has been put on our backlog. We unfortunately have no timelines to share at this point.
Also, to answer you second question, since you are testing OWA, you can simply go to developer tools and place a breakpoint there to test the add-ins and use the console window to check variables data in them.
来源:https://stackoverflow.com/questions/53800823/obtain-attachment-content-from-owa-through-outlook-web-add-in