Class MultipartEntityBuilder
java.lang.Object
org.apache.hc.client5.http.entity.mime.MultipartEntityBuilder
Builder for multipart
HttpEntitys.
This class constructs multipart entities with a boundary determined by either a random UUID
or an explicit boundary set via setBoundary(String).
IMPORTANT: it is responsibility of the caller to validate / sanitize content of body parts. For instance, when using an explicit boundary, it's the caller's responsibility to ensure the body parts do not contain the boundary value, which can prevent the consumer of the entity from correctly parsing / processing the body parts.
- Since:
- 5.0
-
Method Summary
Modifier and TypeMethodDescriptionaddBinaryBody(String name, byte[] b) addBinaryBody(String name, byte[] b, org.apache.hc.core5.http.ContentType contentType, String filename) addBinaryBody(String name, File file) addBinaryBody(String name, File file, org.apache.hc.core5.http.ContentType contentType, String filename) addBinaryBody(String name, InputStream stream) addBinaryBody(String name, InputStream stream, org.apache.hc.core5.http.ContentType contentType, String filename) addBinaryBody(String name, Path path) Adds body with contents from the given source Path.addBinaryBody(String name, Path path, org.apache.hc.core5.http.ContentType contentType, String fileName) Adds body with contents from the given source Path.addEpilogue(String epilogue) Adds an epilogue to the multipart entity being constructed.addParameter(org.apache.hc.core5.http.message.BasicNameValuePair parameter) Add parameter to the currentContentType.addPart(String name, ContentBody contentBody) addPart(MultipartPart multipartPart) addPreamble(String preamble) Adds a preamble to the multipart entity being constructed.addTextBody(String name, String text) addTextBody(String name, String text, org.apache.hc.core5.http.ContentType contentType) org.apache.hc.core5.http.HttpEntitybuild()static MultipartEntityBuildercreate()setBoundary(String boundary) Sets a custom boundary string for the multipart entity.setCharset(Charset charset) setContentType(org.apache.hc.core5.http.ContentType contentType) setMimeSubtype(String subType) setMode(HttpMultipartMode mode)
-
Method Details
-
create
-
setMode
-
setLaxMode
-
setStrictMode
-
setBoundary
Sets a custom boundary string for the multipart entity.If
nullis provided, the builder reverts to its default logic of using a random UUID.IMPORTANT: when setting an explicit boundary, it is responsibility of the caller to validate / sanitize content of body parts to ensure they do not contain the boundary value.
- Parameters:
boundary- the boundary string, ornullto use a random UUID.- Returns:
- this builder instance
-
setMimeSubtype
- Since:
- 4.4
-
setContentType
- Returns:
- this instance.
- Since:
- 4.5
-
addParameter
public MultipartEntityBuilder addParameter(org.apache.hc.core5.http.message.BasicNameValuePair parameter) Add parameter to the currentContentType.- Parameters:
parameter- The name-value pair parameter to add to theContentType.- Returns:
- this instance.
- Since:
- 5.2
-
setCharset
-
addPart
- Since:
- 4.4
-
addPart
-
addTextBody
public MultipartEntityBuilder addTextBody(String name, String text, org.apache.hc.core5.http.ContentType contentType) -
addTextBody
-
addBinaryBody
public MultipartEntityBuilder addBinaryBody(String name, byte[] b, org.apache.hc.core5.http.ContentType contentType, String filename) -
addBinaryBody
-
addBinaryBody
public MultipartEntityBuilder addBinaryBody(String name, File file, org.apache.hc.core5.http.ContentType contentType, String filename) -
addBinaryBody
Adds body with contents from the given source Path.- Parameters:
name- The part name.path- The source path.- Returns:
thisinstance.- Since:
- 5.6
-
addBinaryBody
public MultipartEntityBuilder addBinaryBody(String name, Path path, org.apache.hc.core5.http.ContentType contentType, String fileName) Adds body with contents from the given source Path.- Parameters:
name- The part name.path- The source path.contentType- The content type.fileName- The file name to override the Path's file name.- Returns:
thisinstance.- Since:
- 5.6
-
addBinaryBody
-
addBinaryBody
public MultipartEntityBuilder addBinaryBody(String name, InputStream stream, org.apache.hc.core5.http.ContentType contentType, String filename) -
addBinaryBody
-
addPreamble
Adds a preamble to the multipart entity being constructed. The preamble is the text that appears before the first boundary delimiter. The preamble is optional and may be null.- Parameters:
preamble- The preamble text to add to the multipart entity- Returns:
- this instance.
- Since:
- 5.3
-
addEpilogue
Adds an epilogue to the multipart entity being constructed. The epilogue is the text that appears after the last boundary delimiter. The epilogue is optional and may be null.- Parameters:
epilogue- The epilogue text to add to the multipart entity- Returns:
- this instance.
- Since:
- 5.3
-
build
public org.apache.hc.core5.http.HttpEntity build()
-