Package com.independentsoft.graph
Class Attachment
java.lang.Object
com.independentsoft.graph.Attachment
- All Implemented Interfaces:
ICreatable
- Direct Known Subclasses:
FileAttachment,ItemAttachment,ReferenceAttachment
Abstract base class for attachments in Microsoft Graph.
Attachments can be added to messages, events, and other items. Microsoft Graph supports three types of attachments:
- FileAttachment - A file (such as a document, image, or PDF) attached to a message or event
- ItemAttachment - An Outlook item (message, event, contact) attached to another item
- ReferenceAttachment - A link to a file on OneDrive or other cloud storage
Attachments have size limits:
- File attachments: Up to 150 MB per attachment
- Total attachments per message: Up to 150 MB combined
Example usage:
// Add a file attachment to a message
FileAttachment attachment = new FileAttachment();
attachment.setName("report.pdf");
attachment.setContentType("application/pdf");
attachment.setContentBytes(fileBytes);
Message message = new Message();
message.setSubject("Monthly Report");
message.getAttachments().add(attachment);
client.createMessage(message);
- Since:
- 1.0
- See Also:
- attachment resource type, fileAttachment resource type, itemAttachment resource type
-
Field Summary
Fields -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionGets the MIME type of the attachment.getId()Gets the unique identifier of the attachment.Gets the last modified date/time of the attachment.getName()Gets the name of the attachment.intgetSize()Gets the size of the attachment in bytes.booleanisInline()Checks if the attachment is inline (embedded in message body).voidsetContentType(String contentType)Sets the MIME type of the attachment.voidsetInline(boolean inline)Sets whether the attachment is inline.voidSets the name of the attachment.abstract StringGenerates JSON representation for creating this attachment.
-
Field Details
-
id
-
contentType
-
isInline
protected boolean isInline -
lastModifiedTime
-
name
-
size
protected int size
-
-
Constructor Details
-
Attachment
public Attachment()
-
-
Method Details
-
toCreateJson
Generates JSON representation for creating this attachment.- Specified by:
toCreateJsonin interfaceICreatable- Returns:
- JSON string for creation
-
getId
Gets the unique identifier of the attachment.- Returns:
- The attachment ID
-
getContentType
Gets the MIME type of the attachment.- Returns:
- The content type (e.g., "application/pdf", "image/jpeg")
-
setContentType
Sets the MIME type of the attachment.- Parameters:
contentType- The content type
-
isInline
public boolean isInline()Checks if the attachment is inline (embedded in message body).- Returns:
- true if the attachment is inline, false otherwise
-
setInline
public void setInline(boolean inline)Sets whether the attachment is inline.- Parameters:
inline- true for inline attachment, false for regular attachment
-
getLastModifiedTime
Gets the last modified date/time of the attachment.- Returns:
- The last modified timestamp
-
getName
Gets the name of the attachment.- Returns:
- The file name or attachment name
-
setName
Sets the name of the attachment.- Parameters:
name- The file name or attachment name
-
getSize
public int getSize()Gets the size of the attachment in bytes.- Returns:
- The size in bytes
-