- java.lang.Object
-
- org.eclipse.jetty.client.util.AbstractRequestContent
-
- org.eclipse.jetty.client.util.MultiPartRequestContent
-
- All Implemented Interfaces:
java.io.Closeable,java.lang.AutoCloseable,Request.Content
public class MultiPartRequestContent extends AbstractRequestContent implements java.io.Closeable
A
Request.Contentfor form uploads with the"multipart/form-data"content type.Example usage:
MultiPartRequestContent multiPart = new MultiPartRequestContent(); multiPart.addFieldPart("field", new StringRequestContent("foo"), null); multiPart.addFilePart("icon", "img.png", new PathRequestContent(Paths.get("/tmp/img.png")), null); multiPart.close(); ContentResponse response = client.newRequest("localhost", connector.getLocalPort()) .method(HttpMethod.POST) .content(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>
-
-
Nested Class Summary
-
Nested classes/interfaces inherited from class org.eclipse.jetty.client.util.AbstractRequestContent
AbstractRequestContent.AbstractSubscription, AbstractRequestContent.Producer
-
Nested classes/interfaces inherited from interface org.eclipse.jetty.client.api.Request.Content
Request.Content.Consumer, Request.Content.Subscription
-
-
Constructor Summary
Constructors Constructor Description MultiPartRequestContent()MultiPartRequestContent(java.lang.String boundary)
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description voidaddFieldPart(java.lang.String name, Request.Content content, HttpFields fields)Adds a field part with the givennameas field name, and the givencontentas part content.voidaddFilePart(java.lang.String name, java.lang.String fileName, Request.Content content, HttpFields fields)Adds a file part with the givennameas field name, the givenfileNameas file name, and the givencontentas part content.voidclose()voidfail(java.lang.Throwable failure)Fails this request content, possibly failing and discarding accumulated content that was not demanded.longgetLength()protected Request.Content.SubscriptionnewSubscription(Request.Content.Consumer consumer, boolean emitInitialContent)-
Methods inherited from class org.eclipse.jetty.client.util.AbstractRequestContent
getContentType, subscribe
-
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
-
Methods inherited from interface org.eclipse.jetty.client.api.Request.Content
isReproducible
-
-
-
-
Method Detail
-
getLength
public long getLength()
- Specified by:
getLengthin interfaceRequest.Content- Returns:
- the content length, if known, or -1 if the content length is unknown
-
newSubscription
protected Request.Content.Subscription newSubscription(Request.Content.Consumer consumer, boolean emitInitialContent)
- Specified by:
newSubscriptionin classAbstractRequestContent
-
fail
public void fail(java.lang.Throwable failure)
Description copied from interface:Request.ContentFails this request content, possibly failing and discarding accumulated content that was not demanded.
The failure may be notified to the consumer at a later time, when the consumer demands for content.
Typical failure: the request being aborted by user code, or idle timeouts.
- Specified by:
failin interfaceRequest.Content- Parameters:
failure- the reason of the failure
-
addFieldPart
public void addFieldPart(java.lang.String name, Request.Content content, HttpFields fields)Adds a field part with the given
nameas field name, and the givencontentas part content.The
Content-Typeof this part will be obtained from:- the
Content-Typeheader in thefieldsparameter; otherwise - the
Request.Content.getContentType()
- Parameters:
name- the part namecontent- the part contentfields- the headers associated with this part
- the
-
addFilePart
public void addFilePart(java.lang.String name, java.lang.String fileName, Request.Content content, HttpFields fields)Adds a file part with the given
nameas field name, the givenfileNameas file name, and the givencontentas part content.The
Content-Typeof this part will be obtained from:- the
Content-Typeheader in thefieldsparameter; otherwise - the
Request.Content.getContentType()
- Parameters:
name- the part namefileName- the file name associated to this partcontent- the part contentfields- the headers associated with this part
- the
-
close
public void close()
- Specified by:
closein interfacejava.lang.AutoCloseable- Specified by:
closein interfacejava.io.Closeable
-
-