question

vandanaRatnaparkhi-8204 avatar image
0 Votes"
vandanaRatnaparkhi-8204 asked persistenttest-7723 commented

How to add attachment in event using microsoft graph?

Can I add attachment with the event? Could you please provide me method to add attachment to event and also how to set attachment file path for the same?

microsoft-graph-general
· 2
5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

GraphServiceClient graphClient = GraphServiceClient.builder().authenticationProvider( authProvider ).buildClient();

FileAttachment attachment = new FileAttachment();
attachment.name = "menu.txt";
attachment.contentBytes = Base64.getDecoder().decode("base64bWFjIGFuZCBjaGVlc2UgdG9kYXk=");

graphClient.me().events("AAMkAGI1AAAt9AHjAAA=").attachments()
.buildRequest()
.post(attachment);


(How to set the path of the attached File)



0 Votes 0 ·

1 Answer

MohammedMehtabSiddiqueMINDTREELIMI-9821 avatar image
0 Votes"
MohammedMehtabSiddiqueMINDTREELIMI-9821 answered persistenttest-7723 commented

Hi @vandanaRatnaparkhi-8204 , Thanks for reaching out please refer the below example for

Attachment can be added to a message.attachments

Example:

 FileAttachment fileAttachment = new FileAttachment();
 fileAttachment.name = "Example text file";
 Path path = Paths.get("/Users/user/Desktop/Text.txt");
 fileAttachment.contentBytes = Files.readAllBytes(path);
    
 LinkedList<Attachment> attachmentsList = new LinkedList<Attachment>();
 attachmentsList.add(fileAttachment);
 AttachmentCollectionResponse attachmentCollectionResponse = new AttachmentCollectionResponse();
 attachmentCollectionResponse.value = attachmentsList;
 AttachmentCollectionPage attachmentCollectionPage = new AttachmentCollectionPage(attachmentCollectionResponse, null);
 // add to your message
 message.attachments = attachmentCollectionPage;

Please also refer this DOC


· 1
5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

Thanks for the Solution.

It is working fine at my end.

0 Votes 0 ·