Skip to content

Commit a7b6028

Browse files
Updating inline attachment code
1 parent 7e465c8 commit a7b6028

File tree

1 file changed

+6
-4
lines changed

1 file changed

+6
-4
lines changed

articles/communication-services/quickstarts/email/send-email-advanced/includes/inline-attachments-java.md

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -15,18 +15,20 @@ ms.service: azure-communication-services
1515
We can add an inline attachment by defining one or more EmailAttachment objects, defining a unique `ContentId` for each, and adding them to our EmailMessage object. Read the attachment file and encode it using Base64.
1616

1717
```java
18-
BinaryData jpgInlineAttachmentContent = BinaryData.fromFile(new File("./inline-attachment.png").toPath());
18+
byte[] jpgContent = Files.readAllBytes(new File("./inline-attachment.jpg").toPath());
19+
byte[] jpgEncodedContent = Base64.getEncoder().encodeToString(jpgContent).getBytes();
1920
EmailAttachment jpgInlineAttachment = new EmailAttachment(
2021
"inline-attachment.jpg",
2122
"image/jpeg",
22-
jpgInlineAttachmentContent
23+
BinaryData.fromBytes(jpgEncodedContent)
2324
).setContentId("my-inline-attachment-1");
2425

25-
BinaryData pngInlineAttachmentContent = BinaryData.fromFile(new File("./inline-attachment.png").toPath());
26+
byte[] pngContent = Files.readAllBytes(new File("./inline-attachment.png").toPath());
27+
byte[] pngEncodedContent = Base64.getEncoder().encodeToString(pngContent).getBytes();
2628
EmailAttachment pngInlineAttachment = new EmailAttachment(
2729
"inline-attachment.png",
2830
"image/png",
29-
pngInlineAttachmentContent
31+
BinaryData.fromBytes(pngEncodedContent)
3032
).setContentId("my-inline-attachment-2");
3133
```
3234

0 commit comments

Comments
 (0)