microsoft-graph - Java Method

Ankur Shah 66 Reputation points
2022-04-14T06:02:06.187+00:00

Is there any java method by which I can retrieve content of attachment in outlook: Both item and file attachment?

Microsoft Security Microsoft Graph
0 comments No comments
{count} votes

Accepted answer
  1. JanardhanaVedham-MSFT 3,566 Reputation points
    2022-04-14T06:56:05.24+00:00

    Hi @Ankur Shah ,

    You can use Get attachment Microsoft Graph API to read the properties, relationships, or raw contents of an attachment that is attached to a message in Outlook/Exchange Online.

    Microsoft Graph Java SDK method to get the raw contents of an attachment that is attached to message :

    GraphServiceClient graphClient = GraphServiceClient.builder().authenticationProvider( authProvider ).buildClient();  
      
    InputStream stream = graphClient.me().messages("Message-ID").attachments("Attachment-ID").content()  
     .buildRequest()  
     .get();  
    

    Example :

    192948-image.png

    However as mentioned in this Github issue, it seems there is some known issue with content() method in Microsoft Graph Java SDK and the below alternarive suggestion/workarround was provided in this GitHub issue post. Please refer the same for more information on this.

    final InputStream result = new FileAttachmentStreamRequestBuilder(graphClient.me().messages("id").attachments("id").buildRequest().getRequestUrl().toString() + "/$value", graphClient, null).buildRequest().get();  
    

    You can also refer the below addtional links on this Github Issue for more information:

    https://github.com/microsoftgraph/msgraph-sdk-java/issues/733
    https://github.com/microsoftgraph/msgraph-sdk-java/issues/733#issuecomment-851431912
    https://github.com/microsoftgraph/msgraph-sdk-java/issues/733#issuecomment-851795147
    https://github.com/microsoftgraph/msgraph-sdk-serviceissues/issues/92

    Since this is a Microsoft Java SDK issue, I would advise you to raise an issue with GitHub SDKs support team for any questions on this.

    Hope this helps.

    If the answer is helpful, please click "Accept Answer" and kindly upvote it. If you have any further questions about this answer, please click "Comment".


0 additional answers

Sort by: Most helpful

Your answer

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