简体   繁体   中英

How do I get the raw content of attachment resources from Java SDK in MS Graph API?

I want to use the Java SDK of MS Graph to look up raw content (/$value endpoint) of the attachment.

For /messages resources, I know that raw content can be inquired in the following way.

@Test
void downloadEmlFile() {
    // while empty value, but let's assume there is a value.
    String userId = ""; 
    String messageId = "";

    InputStream inputStream = 
        graphServiceClient.users(userId).messages(messageId)
            .content()
            .buildRequest()
            .get();
}

As you can see above, MS Graph SDK provides an api called .content() for messages.

However, it seems that they do not provide the corresponding api for the attachment resource.

In summary, there are two things I am curious about

  1. Why don't you provide an API like .content() for the attachment resource?
  2. How do I get raw content (/$value) for an attachment?

I think you need to use the FileAttachmentRequestBuilder which has the content method.

@Test
void downloadEmlFile() {
    // while empty value, but let's assume there is a value.
    String userId = ""; 
    String messageId = "";
    String attachmentId = "";

    String requestUrl = graphServiceClient.users(userId).messages(messageId)
            .attachments(attachmentId)
            .getRequestUrl();

    FileAttachmentRequestBuilder fileAttachReqBuilder = new FileAttachmentRequestBuilder(
             requestUrl, 
             graphServiceClient, 
             null)

    InputStream inputStream = fileAttachReqBuilder
                                 .content()
                                 .buildRequest()
                                 .get();
}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM