Get contentBytes() from attachment of an email

Ojas Pawaskar 0 Reputation points

Hi, I am currently working on a Springboot Java project which is using MS graph API version 6.4.0 to read and move mails. After migration from version 2.10.0, and after multiple changes to existing code, I'm getting an error when reading the content of an attachment. Previously to get content the code was
String content = jsonArrayForAttachment.get(i).getAsJsonObject().get("contentBytes");
Where jsonArrayForAttachment is JsonArray and data stored is taken from


Now I have changed above code to the following:
AttachmentCollectionResponse attachmentPage = null;
List<Attachment> attachmentValueList= attachmentPage.getValue();

The issue I'm facing is that there is no method: getContentBytes() inside the attachmentValueList.get(0) Attachment object.
I then use the content String like this : attachmentStream = new ByteArrayInputStream(Base64.getUrlDecoder().decode(content));

I need the contentBytes data to then read the contents of an attachment and then write that content to a new temporary location.

Any help would be helpful.

Microsoft Graph
Microsoft Graph
A Microsoft programmability model that exposes REST APIs and client libraries to access data on Microsoft 365 services.
10,499 questions
0 comments No comments
{count} votes

1 answer

Sort by: Most helpful
  1. Deepanshu Sharma 415 Reputation points Microsoft Vendor

    Hi Ojas,

    you can use :-

    var fileAttachment = attachmentRequest.Result as Microsoft.Graph.FileAttachment;