public class MultiPartContentProvider extends AbstractTypedContentProvider implements AsyncContentProvider, 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.ListenerContentProvider.Typed| Constructor and Description |
|---|
MultiPartContentProvider() |
MultiPartContentProvider(String boundary) |
| Modifier and Type | Method and Description |
|---|---|
void |
addFieldPart(String name,
ContentProvider content,
HttpFields fields)
Adds a field part with the given
name as field name, and the given
content as part content. |
void |
addFilePart(String name,
String fileName,
ContentProvider content,
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() |
Iterator<ByteBuffer> |
iterator() |
void |
setListener(AsyncContentProvider.Listener listener) |
getContentTypeclone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitforEach, spliteratorpublic MultiPartContentProvider()
public MultiPartContentProvider(String boundary)
public void addFieldPart(String name, ContentProvider content, 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(String name, String fileName, ContentProvider content, 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 AsyncContentProviderlistener - the listener to be notified of content availabilitypublic long getLength()
getLength in interface ContentProviderpublic Iterator<ByteBuffer> iterator()
iterator in interface Iterable<ByteBuffer>public void close()
close in interface Closeableclose in interface AutoCloseableCopyright © 1995–2017 Webtide. All rights reserved.