Package com.independentsoft.graph
Class FileAttachment
java.lang.Object
com.independentsoft.graph.Attachment
com.independentsoft.graph.FileAttachment
- All Implemented Interfaces:
ICreatable
Represents a file attached to a message, event, or post in Microsoft Graph.
A FileAttachment carries the binary content of a file directly within the attachment. It is one
of the concrete Attachment types and can be created from a file path, an input stream, or
a byte array, and its content can be saved back to disk or a stream.
Example usage:
// Attach a file to a message
FileAttachment attachment = new FileAttachment("C:/data/report.pdf");
attachment.setContentType("application/pdf");
Message message = new Message();
message.getAttachments().add(attachment);
- Since:
- 1.0
- See Also:
- fileAttachment resource type,
Attachment,ItemAttachment
-
Field Summary
Fields inherited from class com.independentsoft.graph.Attachment
contentType, id, isInline, lastModifiedTime, name, size -
Constructor Summary
ConstructorsConstructorDescriptionInitializes a new instance of the FileAttachment class.FileAttachment(byte[] buffer)Initializes a new instance of the FileAttachment class.FileAttachment(byte[] buffer, String name)Initializes a new instance of the FileAttachment class.FileAttachment(byte[] buffer, String name, String contentType)Initializes a new instance of the FileAttachment class.FileAttachment(JsonObject jsonObject)FileAttachment(InputStream inputStream)Initializes a new instance of the FileAttachment class.FileAttachment(InputStream inputStream, String fileName)Initializes a new instance of the FileAttachment class.FileAttachment(InputStream inputStream, String name, String contentType)Initializes a new instance of the FileAttachment class.FileAttachment(String filePath)Initializes a new instance of the FileAttachment class.FileAttachment(String filePath, String name)Initializes a new instance of the FileAttachment class.FileAttachment(String filePath, String name, String contentType)Initializes a new instance of the FileAttachment class. -
Method Summary
Modifier and TypeMethodDescriptionbyte[]Gets the MIME type of the attachment.Gets the input stream.getName()Gets the name of the attachment.voidsave(OutputStream outputStream)Save.voidSave.voidSave.voidsetContent(byte[] content)voidsetContentId(String contentId)voidsetContentLocation(String contentLocation)byte[]To byte array.Generates JSON representation for creating this attachment.Methods inherited from class com.independentsoft.graph.Attachment
getId, getLastModifiedTime, getSize, isInline, setContentType, setInline, setName
-
Constructor Details
-
FileAttachment
public FileAttachment()Initializes a new instance of the FileAttachment class. -
FileAttachment
Initializes a new instance of the FileAttachment class.- Parameters:
filePath- the file path- Throws:
IOException- Signals that an I/O exception has occurred.
-
FileAttachment
Initializes a new instance of the FileAttachment class.- Parameters:
filePath- the file pathname- the name- Throws:
IOException- Signals that an I/O exception has occurred.
-
FileAttachment
Initializes a new instance of the FileAttachment class.- Parameters:
filePath- the file pathname- the namecontentType- the content type- Throws:
IOException- Signals that an I/O exception has occurred.
-
FileAttachment
Initializes a new instance of the FileAttachment class.- Parameters:
inputStream- the input stream- Throws:
IOException- Signals that an I/O exception has occurred.
-
FileAttachment
Initializes a new instance of the FileAttachment class.- Parameters:
inputStream- the input streamfileName- the file name- Throws:
IOException- Signals that an I/O exception has occurred.
-
FileAttachment
Initializes a new instance of the FileAttachment class.- Parameters:
inputStream- the input streamname- the namecontentType- the content type- Throws:
IOException- Signals that an I/O exception has occurred.
-
FileAttachment
public FileAttachment(byte[] buffer)Initializes a new instance of the FileAttachment class.- Parameters:
buffer- the buffer
-
FileAttachment
Initializes a new instance of the FileAttachment class.- Parameters:
buffer- the buffername- the name
-
FileAttachment
Initializes a new instance of the FileAttachment class.- Parameters:
buffer- the buffername- the namecontentType- the content type
-
FileAttachment
-
-
Method Details
-
toCreateJson
Description copied from class:AttachmentGenerates JSON representation for creating this attachment.- Specified by:
toCreateJsonin interfaceICreatable- Specified by:
toCreateJsonin classAttachment- Returns:
- JSON string for creation
-
save
Save.- Parameters:
filePath- the file path- Throws:
IOException- Signals that an I/O exception has occurred.
-
save
Save.- Parameters:
filePath- the file pathoverwrite- the overwrite- Throws:
IOException- Signals that an I/O exception has occurred.
-
save
Save.- Parameters:
outputStream- the output stream- Throws:
IOException- Signals that an I/O exception has occurred.
-
toByteArray
public byte[] toByteArray()To byte array.- Returns:
- the byte[]
-
getInputStream
Gets the input stream.- Returns:
- the input stream
-
getContent
public byte[] getContent() -
setContent
public void setContent(byte[] content) -
getName
Description copied from class:AttachmentGets the name of the attachment.- Overrides:
getNamein classAttachment- Returns:
- The file name or attachment name
-
getContentType
Description copied from class:AttachmentGets the MIME type of the attachment.- Overrides:
getContentTypein classAttachment- Returns:
- The content type (e.g., "application/pdf", "image/jpeg")
-
getContentId
-
setContentId
-
getContentLocation
-
setContentLocation
-