java.io.Closeable
, java.lang.AutoCloseable
, java.lang.Iterable<java.nio.ByteBuffer>
, ContentProvider
, ContentProvider.Typed
, AsyncContentProvider
public class MultiPartContentProvider extends AbstractTypedContentProvider implements AsyncContentProvider, java.io.Closeable
A ContentProvider
for form uploads with the "multipart/form-data"
content type.
Example usage:
MultiPartContentProvider multiPart = new MultiPartContentProvider(); multiPart.addFieldPart("field", new StringContentProvider("foo"), null); multiPart.addFilePart("icon", "img.png", new PathContentProvider(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>
AsyncContentProvider.Listener
ContentProvider.Typed
Constructor | Description |
---|---|
MultiPartContentProvider() |
|
MultiPartContentProvider(java.lang.String boundary) |
Modifier and Type | Method | Description |
---|---|---|
void |
addFieldPart(java.lang.String name,
ContentProvider content,
org.eclipse.jetty.http.HttpFields fields) |
Adds a field part with the given
name as field name, and the given
content as part content. |
void |
addFilePart(java.lang.String name,
java.lang.String fileName,
ContentProvider content,
org.eclipse.jetty.http.HttpFields fields) |
Adds a file part with the given
name as field name, the given
fileName as file name, and the given content as part content. |
void |
close() |
|
long |
getLength() |
|
java.util.Iterator<java.nio.ByteBuffer> |
iterator() |
|
void |
setListener(AsyncContentProvider.Listener listener) |
getContentType
public MultiPartContentProvider()
public MultiPartContentProvider(java.lang.String boundary)
public void addFieldPart(java.lang.String name, ContentProvider content, org.eclipse.jetty.http.HttpFields fields)
Adds a field part with the given name
as field name, and the given
content
as part content.
The Content-Type
of this part will be obtained from:
Content-Type
header in the fields
parameter; otherwiseContentProvider.Typed.getContentType()
method if the content
parameter
implements ContentProvider.Typed
; otherwisename
- the part namecontent
- the part contentfields
- the headers associated with this partpublic void addFilePart(java.lang.String name, java.lang.String fileName, ContentProvider content, org.eclipse.jetty.http.HttpFields fields)
Adds a file part with the given name
as field name, the given
fileName
as file name, and the given content
as part content.
The Content-Type
of this part will be obtained from:
Content-Type
header in the fields
parameter; otherwiseContentProvider.Typed.getContentType()
method if the content
parameter
implements ContentProvider.Typed
; otherwisename
- the part namefileName
- the file name associated to this partcontent
- the part contentfields
- the headers associated with this partpublic void setListener(AsyncContentProvider.Listener listener)
setListener
in interface AsyncContentProvider
listener
- the listener to be notified of content availabilitypublic long getLength()
getLength
in interface ContentProvider
public java.util.Iterator<java.nio.ByteBuffer> iterator()
iterator
in interface java.lang.Iterable<java.nio.ByteBuffer>
public void close()
close
in interface java.lang.AutoCloseable
close
in interface java.io.Closeable
Copyright © 1995–2018 Webtide. All rights reserved.