nmvision
nmvision

Reputation: 89

Microsoft Graph API in C#: Better way to download message attachments

My currently methodology for downloading message attachments through Graph API is this:

  1. Get the list of messages for the authenticated user.
  2. For each message ID, get the list of attachments associated with it. Only return the name and id.
  3. For each attachment ID, get all of its data. This means that fields such as contentBytes and contentLocation are also returned.
  4. Given the base 64 string in contentBytes, turn it into a file.

From testing, I have found that the time it takes to get the API request in step 3 is my bottleneck. This is due to the large amount of data being returned in the field contentBytes. I will call this the "download".

A file of 2MB can take up to 10 seconds to download on a good connection. When I am limited to a download speed of 5mbps, this can take over a minute to retrieve.

So I have two thoughts I would like to explore:

  1. contentLocation is always null. From my understanding, these file attachments should have a URI here for me to download from. Does anyone know why I am not provided a contentLocation?
  2. If I must stick to working with contentBytes, surely there is an explanation why the download is so slow? What can I do to improve it?

Upvotes: 2

Views: 1155

Answers (1)

Keen Jin
Keen Jin

Reputation: 1138

contentLocation is always null. From my understanding, these file attachments should have a URI here for me to download from. Does anyone know why I am not provided a contentLocation?

I have tried this, and it is null in the response body, we can submit the issue on the github issue

Upvotes: 1

Related Questions