Share via


Multipart Class

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

public class 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

Modifier and Type Field and Description
static final java.lang.String MULTIPART_ENCODING

Default encoding for multi-part requests

Constructor Summary

Constructor Description
Multipart()

Create a new multipart object

Method Summary

Modifier and Type Method and Description
void addFilePart(String name, String contentType, File file)

Add a file part to the multipart body

void addFormData(String name, String contentType, byte[] byteArray)

Add a part to the multipart body

void addHtmlPart(String name, byte[] content)

Add an HTML part to the multipart body

void addPart(String contentType, byte[] byteArray)

Add a part to the multipart body

void addPart(Map<String,String> headers, byte[] content)

Add a part to the multipart body

byte[] content()

Returns a full multipart body byte array

static java.lang.String createContentHeaderValue(String contentValue, Map<String,String> contentDispParameter)

Create content headers value and parameter

java.lang.String getBoundary()

Get the multipart boundary for use in the request header

java.lang.String getContentType()

Get the contentType for use in the request header

HeaderOption header()

Get the Content-Type header to send the multipart request

void setBoundary(String boundary)

Set the multipart boundary for use in the request header

void setContentType(String contentType)

Set the contentType for use in the request header

Methods inherited from java.lang.Object

java.lang.Object.clone java.lang.Object.equals java.lang.Object.finalize java.lang.Object.getClass java.lang.Object.hashCode java.lang.Object.notify java.lang.Object.notifyAll java.lang.Object.toString java.lang.Object.wait java.lang.Object.wait java.lang.Object.wait

Field Details

MULTIPART_ENCODING

public static final String MULTIPART_ENCODING

Default encoding for multi-part requests

Constructor Details

Multipart

public Multipart()

Create a new multipart object

Method Details

addFilePart

public void addFilePart(String name, String contentType, File file)

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:

java.io.IOException - Throws an exception if the output stream cannot be written to

addFormData

public void addFormData(String name, String contentType, byte[] byteArray)

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:

java.io.IOException - Throws an exception if the output stream cannot be written to

addHtmlPart

public void addHtmlPart(String name, byte[] content)

Add an HTML part to the multipart body

Parameters:

name - The name of the part
content - The HTML body for the part

Throws:

java.io.IOException - Throws an exception if the output stream cannot be written to

addPart

public void addPart(String contentType, byte[] byteArray)

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:

java.io.IOException - Throws an exception if the output stream cannot be written to

addPart

public void addPart(Map headers, byte[] content)

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:

java.io.IOException - Throws an exception if the output stream cannot be written to

content

public byte[] content()

Returns a full multipart body byte array

Returns:

The byte[] representation of the multipart object

Throws:

java.io.IOException - Throws an exception if the output stream cannot be written to

createContentHeaderValue

public static String createContentHeaderValue(String contentValue, Map 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

getBoundary

public String getBoundary()

Get the multipart boundary for use in the request header

Returns:

the multipart boundary

getContentType

public String getContentType()

Get the contentType for use in the request header

Returns:

the multipart Content-Type

header

public HeaderOption header()

Get the Content-Type header to send the multipart request

Returns:

the multipart header option

setBoundary

public void setBoundary(String boundary)

Set the multipart boundary for use in the request header

Parameters:

boundary - The multipart boundary

setContentType

public void setContentType(String contentType)

Set the contentType for use in the request header

Parameters:

contentType - The multipart Content-Type

Applies to