Share via

Graph API returns wrong size for email attachments

Alan Dzday 5 Reputation points
2025-04-11T07:29:23.49+00:00

Hi,

I'm using the Graph API to load metadata for message attachments via the endpoint /me/messages/{id}/attachments/{id}. However, the size property returned doesn't match the actual size of the file when downloaded using the raw data route (/me/messages/{id}/attachments/{id}/$value). Additionally, the response headers don't include a Content-Length value. How can I accurately determine the correct size of the attachment?

Microsoft Security | Microsoft Graph
0 comments No comments

1 answer

Sort by: Most helpful
  1. Vasil Michev 127K Reputation points MVP Volunteer Moderator
    2025-04-12T14:46:38.54+00:00

    This might be due to the encoding bloat, is the difference in actual/reported size you are seeing around 33-37% (depending on which value you use as base)? Here's an insert from the Exchange server's documentation about this:

    For any message size limit, you need to set a value that's larger than the actual size you want enforced. This accounts for the Base64 encoding of attachments and other binary data. Base64 encoding increases the size of the message by approximately 33%, so the value you specify should be approximately 33% larger than the actual message size you want enforced. For example, if you specify a maximum message size value of 64 MB, you can expect a realistic maximum message size of approximately 48 MB.

    Was this answer helpful?


Your answer

Answers can be marked as 'Accepted' by the question author and 'Recommended' by moderators, which helps users know the answer solved the author's problem.