Class FileAttachment

java.lang.Object
com.independentsoft.graph.Attachment
com.independentsoft.graph.FileAttachment
All Implemented Interfaces:
ICreatable

public class FileAttachment extends Attachment
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
  • Constructor Details

    • FileAttachment

      public FileAttachment()
      Initializes a new instance of the FileAttachment class.
    • FileAttachment

      public FileAttachment(String filePath) throws IOException
      Initializes a new instance of the FileAttachment class.
      Parameters:
      filePath - the file path
      Throws:
      IOException - Signals that an I/O exception has occurred.
    • FileAttachment

      public FileAttachment(String filePath, String name) throws IOException
      Initializes a new instance of the FileAttachment class.
      Parameters:
      filePath - the file path
      name - the name
      Throws:
      IOException - Signals that an I/O exception has occurred.
    • FileAttachment

      public FileAttachment(String filePath, String name, String contentType) throws IOException
      Initializes a new instance of the FileAttachment class.
      Parameters:
      filePath - the file path
      name - the name
      contentType - the content type
      Throws:
      IOException - Signals that an I/O exception has occurred.
    • FileAttachment

      public FileAttachment(InputStream inputStream) throws IOException
      Initializes a new instance of the FileAttachment class.
      Parameters:
      inputStream - the input stream
      Throws:
      IOException - Signals that an I/O exception has occurred.
    • FileAttachment

      public FileAttachment(InputStream inputStream, String fileName) throws IOException
      Initializes a new instance of the FileAttachment class.
      Parameters:
      inputStream - the input stream
      fileName - the file name
      Throws:
      IOException - Signals that an I/O exception has occurred.
    • FileAttachment

      public FileAttachment(InputStream inputStream, String name, String contentType) throws IOException
      Initializes a new instance of the FileAttachment class.
      Parameters:
      inputStream - the input stream
      name - the name
      contentType - 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

      public FileAttachment(byte[] buffer, String name)
      Initializes a new instance of the FileAttachment class.
      Parameters:
      buffer - the buffer
      name - the name
    • FileAttachment

      public FileAttachment(byte[] buffer, String name, String contentType)
      Initializes a new instance of the FileAttachment class.
      Parameters:
      buffer - the buffer
      name - the name
      contentType - the content type
    • FileAttachment

      public FileAttachment(JsonObject jsonObject)
  • Method Details

    • toCreateJson

      public String toCreateJson()
      Description copied from class: Attachment
      Generates JSON representation for creating this attachment.
      Specified by:
      toCreateJson in interface ICreatable
      Specified by:
      toCreateJson in class Attachment
      Returns:
      JSON string for creation
    • save

      public void save(String filePath) throws IOException
      Save.
      Parameters:
      filePath - the file path
      Throws:
      IOException - Signals that an I/O exception has occurred.
    • save

      public void save(String filePath, boolean overwrite) throws IOException
      Save.
      Parameters:
      filePath - the file path
      overwrite - the overwrite
      Throws:
      IOException - Signals that an I/O exception has occurred.
    • save

      public void save(OutputStream outputStream) throws IOException
      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

      public InputStream getInputStream()
      Gets the input stream.
      Returns:
      the input stream
    • getContent

      public byte[] getContent()
    • setContent

      public void setContent(byte[] content)
    • getName

      public String getName()
      Description copied from class: Attachment
      Gets the name of the attachment.
      Overrides:
      getName in class Attachment
      Returns:
      The file name or attachment name
    • getContentType

      public String getContentType()
      Description copied from class: Attachment
      Gets the MIME type of the attachment.
      Overrides:
      getContentType in class Attachment
      Returns:
      The content type (e.g., "application/pdf", "image/jpeg")
    • getContentId

      public String getContentId()
    • setContentId

      public void setContentId(String contentId)
    • getContentLocation

      public String getContentLocation()
    • setContentLocation

      public void setContentLocation(String contentLocation)