Package org.eclipse.jetty.client
Class MultiPartRequestContent
java.lang.Object
org.eclipse.jetty.http.MultiPart.AbstractContentSource
org.eclipse.jetty.http.MultiPartFormData.ContentSource
org.eclipse.jetty.client.MultiPartRequestContent
- All Implemented Interfaces:
Closeable
,AutoCloseable
,Request.Content
,Content.Source
public class MultiPartRequestContent
extends MultiPartFormData.ContentSource
implements Request.Content
A Request.Content
for form uploads with the "multipart/form-data"
content type.
Example usage:
MultiPartRequestContent multiPart = new MultiPartRequestContent(); multiPart.addPart(new MultiPart.ContentSourcePart("field", null, HttpFields.EMPTY, new StringRequestContent("foo"))); multiPart.addPart(new MultiPart.PathPart("icon", "img.png", HttpFields.EMPTY, Path.of("/tmp/img.png"))); multiPart.close(); ContentResponse response = client.newRequest("localhost", connector.getLocalPort()) .method(HttpMethod.POST) .body(multiPart) .send();
The above example would be the equivalent of submitting this form:
<form method="POST" enctype="multipart/form-data" accept-charset="UTF-8">
<input type="text" name="field" value="foo" />
<input type="file" name="icon" />
</form>
-
Constructor Summary
-
Method Summary
Methods inherited from class org.eclipse.jetty.http.MultiPart.AbstractContentSource
addPart, close, demand, fail, getBoundary, getLength, getPartHeadersMaxLength, read, setPartHeadersMaxLength
-
Constructor Details
-
MultiPartRequestContent
public MultiPartRequestContent() -
MultiPartRequestContent
-
-
Method Details
-
getContentType
- Specified by:
getContentType
in interfaceRequest.Content
- Returns:
- the content type string such as "application/octet-stream" or
"application/json;charset=UTF8", or null if the
Content-Type
header must not be set
-
customizePartHeaders
- Overrides:
customizePartHeaders
in classMultiPartFormData.ContentSource
-