@Beta
@NotThreadSafe
public class MultipartFormDataContent
extends com.google.api.client.http.MultipartContent
MultipartContent that sets the
media type to "multipart/form-data" and defaults to
DEFAULT_BOUNDARY as a boundary string.
The generated content output differs from the superclass one to specifically
meet the "multipart/form-data" RFC specifications, for example
omitting redundant headers in the content parts (except for nested
"multipart" parts).
Shortcut method #addPart(Part, String, String) is provided in order
to easily set name and file name for the mandatory header
"Content-Disposition". This header can be manually set in each
part's headers using the following format (but in this case no consistency
checks are made and the request will most likely fail):
Content-Disposition: form-data; name="user"
Specifications on the "content-disposition" header (RFC 2183):
http://tools.ietf.org/html/rfc2183
http://chxo.com/be2/20050724_93bf.htmlhttp://www.faqs.org/rfcs/rfc1867.html| Modifier and Type | Field and Description |
|---|---|
protected static java.lang.String |
DEFAULT_BOUNDARY |
| Constructor and Description |
|---|
MultipartFormDataContent()
Creates a new empty
MultipartFormDataContent. |
| Modifier and Type | Method and Description |
|---|---|
MultipartFormDataContent |
addPart(com.google.api.client.http.MultipartContent.Part part) |
MultipartFormDataContent |
addPart(com.google.api.client.http.MultipartContent.Part part,
java.lang.String dispositionName,
java.lang.String dispositionFilename)
Adds an HTTP multipart part.
|
protected static com.google.api.client.http.HttpMediaType |
getMultipartFormDataMediaType()
Factory method to create
HttpMediaType with media type
"multipart/form-data" |
MultipartFormDataContent |
setBoundary(java.lang.String boundary)
Sets the boundary string to use (must be not null)
If this is not called, the boundary defaults to
DEFAULT_BOUNDARY |
MultipartFormDataContent |
setContentParts(java.util.Collection<? extends com.google.api.client.http.HttpContent> contentParts) |
MultipartFormDataContent |
setMediaType(com.google.api.client.http.HttpMediaType mediaType) |
MultipartFormDataContent |
setParts(java.util.Collection<com.google.api.client.http.MultipartContent.Part> parts) |
void |
writeTo(java.io.OutputStream out) |
getBoundary, getParts, retrySupportedprotected static final java.lang.String DEFAULT_BOUNDARY
public MultipartFormDataContent()
MultipartFormDataContent.protected static final com.google.api.client.http.HttpMediaType getMultipartFormDataMediaType()
HttpMediaType with media type
"multipart/form-data"public void writeTo(java.io.OutputStream out)
throws java.io.IOException
writeTo in interface com.google.api.client.http.HttpContentwriteTo in interface com.google.api.client.util.StreamingContentwriteTo in class com.google.api.client.http.MultipartContentjava.io.IOExceptionpublic MultipartFormDataContent addPart(@Nonnull com.google.api.client.http.MultipartContent.Part part, @Nonnull java.lang.String dispositionName, @Nullable java.lang.String dispositionFilename)
"content-disposition"
headers for the content (as per RFC 2183 par. 2). If the header is
already specified in the added part, its value is overridden.part - The Part to add to the contentdispositionName - The name of the part (usually the field name in a web form)dispositionFilename - The optional filename of the part (usually for adding a
FileContent part)public MultipartFormDataContent addPart(@Nonnull com.google.api.client.http.MultipartContent.Part part)
addPart in class com.google.api.client.http.MultipartContentpublic MultipartFormDataContent setParts(@Nonnull java.util.Collection<com.google.api.client.http.MultipartContent.Part> parts)
setParts in class com.google.api.client.http.MultipartContentpublic MultipartFormDataContent setContentParts(@Nonnull java.util.Collection<? extends com.google.api.client.http.HttpContent> contentParts)
setContentParts in class com.google.api.client.http.MultipartContentpublic final MultipartFormDataContent setMediaType(@Nullable com.google.api.client.http.HttpMediaType mediaType)
setMediaType in class com.google.api.client.http.MultipartContentpublic MultipartFormDataContent setBoundary(@Nonnull java.lang.String boundary)
DEFAULT_BOUNDARYsetBoundary in class com.google.api.client.http.MultipartContentboundary - The new boundary for the contentjava.lang.NullPointerException - if boundary is null