Reputation: 91
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
Upvotes: 2
Views: 954
Reputation: 1
You can use the FileAttachment class.
FileAttachment attachment = (FileAttachment) message.attachments.getCurrentPage().get(0);
attachment.contentBytes
Upvotes: 0
Reputation: 20768
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();
}
Upvotes: 2