Package com.microsoft.graph.core
Class Multipart
java.lang.Object
com.microsoft.graph.core.Multipart
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 Summary
Fields -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionvoidaddFilePart(String name, String contentType, File file) Add a file part to the multipart bodyvoidaddFormData(String name, String contentType, byte[] byteArray) Add a part to the multipart bodyvoidaddHtmlPart(String name, byte[] content) Add an HTML part to the multipart bodyvoidAdd a part to the multipart bodyvoidAdd a part to the multipart bodybyte[]content()Returns a full multipart body byte arraystatic StringcreateContentHeaderValue(String contentValue, Map<String, String> contentDispParameter) Create content headers value and parameterGet the multipart boundary for use in the request headerGet the contentType for use in the request headerheader()Get the Content-Type header to send the multipart requestvoidsetBoundary(String boundary) Set the multipart boundary for use in the request headervoidsetContentType(String contentType) Set the contentType for use in the request header
-
Field Details
-
MULTIPART_ENCODING
Default encoding for multi-part requests- See Also:
-
-
Constructor Details
-
Multipart
public Multipart()Create a new multipart object
-
-
Method Details
-
getBoundary
Get the multipart boundary for use in the request header- Returns:
- the multipart boundary
-
setBoundary
Set the multipart boundary for use in the request header- Parameters:
boundary- The multipart boundary
-
getContentType
Get the contentType for use in the request header- Returns:
- the multipart Content-Type
-
setContentType
Set the contentType for use in the request header- Parameters:
contentType- The multipart Content-Type
-
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 valuecontentDispParameter- 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 partcontentType- 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
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 IOExceptionAdd 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 stringcontent- The byte[] contents of the resource- Throws:
IOException- Throws an exception if the output stream cannot be written to
-
addHtmlPart
Add an HTML part to the multipart body- Parameters:
name- The name of the partcontent- 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 partcontentType- 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
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
-