Class Multipart

java.lang.Object
com.microsoft.graph.core.Multipart

public class Multipart extends Object
Helper for submitting multipart data This follows the Network Working Group's RFC on multipart/form-data posting format: https://www.ietf.org/rfc/rfc2388.txt
  • Field Details

    • MULTIPART_ENCODING

      public static final String MULTIPART_ENCODING
      Default encoding for multi-part requests
      See Also:
      Constant Field Values
  • Constructor Details

    • Multipart

      public Multipart()
      Create a new multipart object
  • Method Details

    • getBoundary

      @Nonnull public String getBoundary()
      Get the multipart boundary for use in the request header
      Returns:
      the multipart boundary
    • setBoundary

      public void setBoundary(@Nonnull String boundary)
      Set the multipart boundary for use in the request header
      Parameters:
      boundary - The multipart boundary
    • getContentType

      @Nonnull public String getContentType()
      Get the contentType for use in the request header
      Returns:
      the multipart Content-Type
    • setContentType

      public void setContentType(@Nonnull String contentType)
      Set the contentType for use in the request header
      Parameters:
      contentType - The multipart Content-Type
    • header

      @Nonnull public HeaderOption header()
      Get the Content-Type header to send the multipart request
      Returns:
      the multipart header option
    • createContentHeaderValue

      @Nonnull public static String createContentHeaderValue(@Nonnull String contentValue, @Nullable Map<String,​String> contentDispParameter)
      Create content headers value and parameter
      Parameters:
      contentValue - The content header value
      contentDispParameter - Map containing content paramter's key and value pair
      Returns:
      content header value and parameter string
    • addFormData

      public void addFormData(@Nonnull String name, @Nonnull String contentType, @Nonnull byte[] byteArray) throws IOException
      Add a part to the multipart body
      Parameters:
      name - The name of the part
      contentType - The MIME type (text/html, video/mp4, etc.)
      byteArray - The byte[] contents of the resource
      Throws:
      IOException - Throws an exception if the output stream cannot be written to
    • addPart

      public void addPart(@Nonnull String contentType, @Nonnull byte[] byteArray) throws IOException
      Add a part to the multipart body
      Parameters:
      contentType - The MIME type (text/html, video/mp4, etc.)
      byteArray - The byte[] contents of the resource
      Throws:
      IOException - Throws an exception if the output stream cannot be written to
    • addPart

      public void addPart(@Nonnull Map<String,​String> headers, @Nonnull byte[] content) throws IOException
      Add a part to the multipart body
      Parameters:
      headers - Map containing Header's header-name(eg: Content-Disposition, Content-Type, etc..) and header's value-parameter string
      content - The byte[] contents of the resource
      Throws:
      IOException - Throws an exception if the output stream cannot be written to
    • addHtmlPart

      public void addHtmlPart(@Nonnull String name, @Nonnull byte[] content) throws IOException
      Add an HTML part to the multipart body
      Parameters:
      name - The name of the part
      content - The HTML body for the part
      Throws:
      IOException - Throws an exception if the output stream cannot be written to
    • addFilePart

      public void addFilePart(@Nonnull String name, @Nonnull String contentType, @Nonnull File file) throws IOException
      Add a file part to the multipart body
      Parameters:
      name - The name of the part
      contentType - The MIME type of the file (application/pdf, video/mp4, etc.)
      file - The file
      Throws:
      IOException - Throws an exception if the output stream cannot be written to
    • content

      @Nullable public byte[] content() throws IOException
      Returns a full multipart body byte array
      Returns:
      The byte[] representation of the multipart object
      Throws:
      IOException - Throws an exception if the output stream cannot be written to