OfficeDev / office-js

A repo and NPM package for Office.js, corresponding to a copy of what gets published to the official "evergreen" Office.js CDN, at https://appsforoffice.microsoft.com/lib/1/hosted/office.js.
https://learn.microsoft.com/javascript/api/overview
Other
648 stars 92 forks source link

getAttachmentContentAsync delivers attachments without content #3897

Closed hmuris closed 4 months ago

hmuris commented 5 months ago

Hello,

we have detected this problem earlier today, the method getAttachmentContentAsync which previously was delivering the content, is not doing it any more. image

After calling item.getAttachmentsAsync (Compose) or getting the list of attachments from item.attachments (Read), we call item.getAttachmentContentAsync in order to get the content. Although this was working it is no longer. Question is, how can we get the content of attachments, if this changed.

ajays-msft commented 5 months ago

@hmuris - Which platform and version of outlook are you having this problem? Can you please provide a sample scriptlab snippet which will help us get a repro and investigate further?

hmuris commented 5 months ago

Ok, I need a bit time, please don't close.

hmuris commented 5 months ago

Here is the method to get the attachments: private getMyAttachment(item: (Office.Item & Office.ItemCompose & Office.ItemRead & Office.Message & Office.MessageCompose & Office.MessageRead & Office.Appointment & Office.AppointmentCompose & Office.AppointmentRead), attachmentInfos: any[], index: number): Observable<any[]> { return new Observable<any[]>((observer) => { let attachments: any[] = []; if (index + 1 <= attachmentInfos.length) { item.getAttachmentContentAsync(attachmentInfos[index].id, (attachmentContentResult: any) => { if (attachmentContentResult.status !== Office.AsyncResultStatus.Failed) { let attachment = attachmentContentResult.value; let attachmentInfo = attachmentInfos[index]; attachments.push({ name: attachmentInfo.name, attachmentId: attachmentInfo.id, data: attachment.content }); this.getMyAttachment(item, attachmentInfos, index + 1).subscribe((attachmentResult) => { attachments = attachments.concat(attachmentResult); observer.next(attachments); }); } else { observer.error('Failed to get attachment content.'); } }); } else { observer.next(attachments); } }); }

and here is the call of it: if (item && (item.getItemIdAsync === undefined || typeof item.getItemIdAsync === undefined)) { this.getMyAttachment(item, item.attachments, 0).subscribe((myAttachments)=>{ console.log('Here are attachments with no data'); }); }

The call is performed on the button click in the app.component.ts.

For the email with two attachments, I get this: image

Here is the manifest.

Since the code is not formated with line breaks, here it is as a picture: image

hmuris commented 5 months ago

Hello, is there any news about this topic? Again, this was working without any problem, and it is no longer so.

exextoc commented 5 months ago

@hmuris, what is the attachment type where you see this issue. Is it any of the blocked types listed here - https://support.microsoft.com/en-us/office/blocked-attachments-in-outlook-434752e1-02d3-4e90-9124-8b81e49a8519 ?

hmuris commented 5 months ago

No, it is a png, as an inline and as regular attachment.

exextoc commented 5 months ago

@hmuris Would it be possible to share a repro video. This would help us repro the issue.

Suntechnick commented 4 months ago

We also encounter this issue. If that may help, we constantly get this issue when we try make multiple (up to 50-60) concurrent content requests.

ajays-msft commented 4 months ago

@Suntechnick @hmuris - I understand you are having an issue with office-js api. But, are you able to download attachments directly from the email from the UI?

Suntechnick commented 4 months ago

@ajays-msft I haven't tried it, but I assume it won't be helpful because this issue is inconsistent. What I mean is that in some cases the content is properly acquired and in some cases it isn't. I was able to find a workaround for this issue that works as following: in case when getAttachmentContentAsync finishes with succeeded status and empty content, we retry the getAttachmentContentAsync request until the proper content is acquired.

exextoc commented 4 months ago

@hmuris Can you help us with the platform and version of outlook are you having this problem? Also share a repro video, it will help us understand the problem.

Suntechnick commented 4 months ago

For us the issue was only present in Outlook for the Web.

hmuris commented 4 months ago

Hi, yes, we are developing the addin, visible in manifest, which is using API version 12, meaning it cannot be desktop version, or?

hmuris commented 4 months ago

I don't understand what should I record? Here is the code: let item = Office.context.mailbox.item; if(item && item.attachments && item.attachments.length > 0){ item.getAttachmentContentAsync(item.attachments[0].id, (clbk)=>{ let attachment = clbk.value; //attachment.content is empty debugger; }); }

ajays-msft commented 4 months ago

@hmuris @Suntechnick - You mentioned the issue is inconsistent. Is it inconsistent always for the same type of attachment?

hmuris commented 4 months ago

I didn't mention that it is inconsistent. For us, it is always not delivering the content.

On Wed, Jan 17, 2024, 7:40 AM Ajay Suri @.***> wrote:

@hmuris https://github.com/hmuris @Suntechnick https://github.com/Suntechnick - You mentioned the issue is inconsistent. Is it inconsistent always for the same type of attachment?

— Reply to this email directly, view it on GitHub https://github.com/OfficeDev/office-js/issues/3897#issuecomment-1895089670, or unsubscribe https://github.com/notifications/unsubscribe-auth/ABGP4QHQX6L66Q64Z2ADUZLYO5W43AVCNFSM6AAAAABAMTMY7SVHI2DSMVQWIX3LMV43OSLTON2WKQ3PNVWWK3TUHMYTQOJVGA4DSNRXGA . You are receiving this because you were mentioned.Message ID: @.***>

Suntechnick commented 4 months ago

@ajays-msft I'll provide more details for our case. We are attaching 59 files to the email (these 59 files are the copies of the same .doc file). Then we simultaneously request the content for ALL of the 59 attachments and for some of them we encounter the issue described in this ticket. What I meant by "inconsistency" is that the number of attachments that have empty content is arbitrary (e.g., sometimes it's 3, sometimes it's 2 and sometimes it's 6 and so on...), and the attachments that have empty content are arbitrary as well (e.g., sometimes it's attachments #2, #59 and #29; sometimes it's attachments #3 and #48 and so on...).

Not sure if that may be helpful, but we noticed that in devtools network tab, some of the attachments content requests are failed with 503 code. We are not sure that's related to the issue from this ticket because the results of getAttachmentContentAsync requests always have a succeeded status.

ajays-msft commented 4 months ago

Thank you. To summarize @hmuris - getAttachmentContentAsync never works for you. Please confirm if there is any setting on the server side to block downloads for attachments in OWA. @Suntechnick - It fails certain times when you have several attachments. When you mean simultaneously request for all files, I am assuming you are waiting for attachment event to be completed, and only then trying to fetch the attachment one after another. Is that the right understanding?

Suntechnick commented 4 months ago

@ajays-msft No, all the requests for the content are sent at the same time. Making it sequentially is not desired in our case because it will make things slower and we are already limited by the on-send event 5 minutes limit.

ajays-msft commented 4 months ago

Thank you @Suntechnick. Noted. Is this issue reproduced in other platforms (Windows Outlook, Mac Outlook), or is this specific to Outlook in Browser?

Suntechnick commented 4 months ago

@ajays-msft We only encountered this issue on Web Outlook. It was not replicated on Outlook Desktop.

hmuris commented 4 months ago

I confirm that there is no setting blocking attachment download. I have accounts on different domains, and this does not work on either of them.

ajays-msft commented 4 months ago

@hmuris - Getting attachments is different in read and compose. The code you pointed to will work in read mode only. For more details on getting attachments, here is the documentation.

Read Mode: https://learn.microsoft.com/en-us/office/dev/add-ins/outlook/get-attachments-of-an-outlook-item

Compose Mode: https://learn.microsoft.com/en-us/office/dev/add-ins/outlook/add-and-remove-attachments-to-an-item-in-a-compose-form

ajays-msft commented 4 months ago

@Suntechnick - Can you please create a new github issue for your case since these are different problems?

hmuris commented 4 months ago

I know it is different. It is easier to show this example. Still, this code is not working in read mode.

On Thu, Jan 18, 2024, 5:39 AM Ajay Suri @.***> wrote:

@Suntechnick https://github.com/Suntechnick - Can you please create a new github issue for your case since these are different problems?

— Reply to this email directly, view it on GitHub https://github.com/OfficeDev/office-js/issues/3897#issuecomment-1897783867, or unsubscribe https://github.com/notifications/unsubscribe-auth/ABGP4QHZ736BVSSL4BY336LYPCRPTAVCNFSM6AAAAABAMTMY7SVHI2DSMVQWIX3LMV43OSLTON2WKQ3PNVWWK3TUHMYTQOJXG44DGOBWG4 . You are receiving this because you were mentioned.Message ID: @.***>

ajays-msft commented 4 months ago

Thanks @hmuris. Unfortunately, I am not able get a repro. Can I assume that you are able to manually download the attachment directly from OWA Mail? Please confirm.

https://learn.microsoft.com/en-us/exchange/troubleshoot/outlook-on-the-web-issues/cannot-open-attachments

Suntechnick commented 4 months ago

@Suntechnick - Can you please create a new github issue for your case since these are different problems?

Not sure these are different problems because we face exactly the same issue that's described in this ticket. Checking the @hmuris code example, I think that's very similar to what I've tried to describe earlier and how it works in our addin. In short: multiple concurrent requests to get attachment's content cause some of them to unexpectedly return an empty content.

ajays-msft commented 4 months ago

@Suntechnick - In your case it fails at times. But for @hmuris it always fails.

Suntechnick commented 4 months ago

@ajays-msft probably my explanation was not clear enough. The issue occurs consistently under certain circumstances that I described above, but the results of this issue may wary (that's what I meant by "inconsistent behavior").

ajays-msft commented 4 months ago

@Suntechnick - For @hmuris If the call is made 50 times, all the time it fails.

But for you it will fail some x number of times out of 50 times, and x may vary for each run. That is my understanding. That is what I meant by inconsistent failures. I agree that it you are consistently seeing inconsistent failures.

hmuris commented 4 months ago

I can download attachment. Here is the example when composing the email:

public doAttachments() { let item = Office.context.mailbox.item; if (item) { item.getAttachmentsAsync((officeJSAttachments) => { item?.getAttachmentContentAsync(officeJSAttachments.value[0].id, (clbk)=>{ let attachment = clbk.value; //attachment.content is empty debugger; }); }); } }

Result is same like for reading emails. image image

hmuris commented 4 months ago

One more thing, in the moment of executing the getAttachmentContentAsync I get following 404 Not Found: image Here is the request: https://attachments.office.net/owa/CKaufmann%40business-app.com/service.svc/s/GetFileAttachment?id=AAMkAGZhNWJjY2YxLTlmNDAtNDY2YS04NGU2LTVmYWFiZGMwMWRiMQBGAAAAAABIg0dsM1r8RZZaZjVtan8rBwBB1SDFPMp%2FR5PuJGZsHf6zAAAAAAEPAABB1SDFPMp%2FR5PuJGZsHf6zAAI2c9VyAAABEgAQAKkFn6nkOZtOgJVJY2IXUXY%3D&token=eyJhbGciOiJSUzI1NiIsImtpZCI6IkU1RDJGMEY4REE5M0I2NzA5QzQzQTlFOEE2MTQzQzAzRDYyRjlBODAiLCJ0eXAiOiJKV1QiLCJ4NXQiOiI1ZEx3LU5xVHRuQ2NRNm5vcGhROEE5WXZtb0EifQ.eyJvcmlnaW4iOiJodHRwczovL291dGxvb2sub2ZmaWNlLmNvbSIsInVjIjoiMTk1MGFhODUwZWQ4NDllOWJhNzBhMmJiNjkxYzM5ODYiLCJzaWduaW5fc3RhdGUiOiJbXCJrbXNpXCJdIiwidmVyIjoiRXhjaGFuZ2UuQ2FsbGJhY2suVjEiLCJhcHBjdHhzZW5kZXIiOiJPd2FEb3dubG9hZEAxNGZiNzhiZC0xMGM2LTQ5MDctYTNlNy1mODA4MmQyZjc2ZmYiLCJpc3NyaW5nIjoiU0lQIiwiYXBwY3R4Ijoie1wibXNleGNocHJvdFwiOlwib3dhXCIsXCJwdWlkXCI6XCIxMTUzODAxMTIwMjM0NDI5NDM1XCIsXCJzY29wZVwiOlwiT3dhRG93bmxvYWRcIixcIm9pZFwiOlwiYjc5NjJkZjYtNjc4Ni00N2UzLWJhNjMtNjBmZDhlNzJiNTQyXCIsXCJwcmltYXJ5c2lkXCI6XCJTLTEtNS0yMS0xODc1NjU3MTcwLTQxMDY2NTQ5NDgtMjUwNTI2NDE4Mi0yMjQwNDUwOFwifSIsIm5iZiI6MTcwNTU4MTIyMSwiZXhwIjoxNzA1NTgxODIxLCJpc3MiOiIwMDAwMDAwMi0wMDAwLTBmZjEtY2UwMC0wMDAwMDAwMDAwMDBAMTRmYjc4YmQtMTBjNi00OTA3LWEzZTctZjgwODJkMmY3NmZmIiwiYXVkIjoiMDAwMDAwMDItMDAwMC0wZmYxLWNlMDAtMDAwMDAwMDAwMDAwL2F0dGFjaG1lbnRzLm9mZmljZS5uZXRAMTRmYjc4YmQtMTBjNi00OTA3LWEzZTctZjgwODJkMmY3NmZmIiwiaGFwcCI6Im93YSJ9.UQZWCUyno8mvxw-ql1V3vEHg3xH29_ylhFi0FS3_Pkl9-VSJMFwy0CgpvaE6ATJizh-YsYZmXVqy-YxFjMDOgHeDK89bPq6VngEyhxhQm0vPfqlhKtfWORRTnM9M2fssmgRsKkTogCGMRtBIlHieKWvE--vhIMOeWZhh3Cygfr20yOxSFJ-8wLpSHrhl_Py-tRMpurFpr0tVeE_6IbgcpE0hiq9hWjs4Cm3MpFJL98DezkBGP7PPXssDmExtBZtgO9k-Vc_HwLzwhqNE_mMUIiNyf9vgd3Pm88avgC4fSOEe7a6qF9Lp0HyV1jJUkJdegUt73GLflIE2_ciGCBf_JA&X-OWA-CANARY=UVU5NhHc60yk9SkKAIGbcNBy8uUhGNwYVxfah7hFYZM2hi_D1gU5Xt918vg7TgpOI549ea_7Gao.&owa=outlook.office.com&scriptVer=20240105004.04&clientId=178F9D7EB27549C6A6DD3A0C78D361DA&isDownload=true&animation=true&asDataUri=true

hmuris commented 4 months ago

Any news here?

exextoc commented 4 months ago

We are not able to repro this issue at our end. Can you please share the test tenant at OutlookExtensibility@M365x53858506.onmicrosoft.com so that we can repro the issue and debug it at our end.

hmuris commented 4 months ago

@exextoc I will modify the add-in so that you can install it on your side.

hmuris commented 4 months ago

@exextoc I have found the problem. We are using makeEwsRequestAsync to save and read extended property data. In order to save data, first we have to make a request to get the change key and then the second request to set the data. The attachments were broken when we had two of these requests running at "the same time". Once we changed it to observable, and waited explicitly with second, attachments were delivered correctly.