public class

MultipartFormDataContent

extends MultipartContent
java.lang.Object
   ↳ com.google.api.client.http.AbstractHttpContent
     ↳ com.google.api.client.http.MultipartContent
       ↳ com.google.api.client.http.MultipartFormDataContent

Class Overview

Serializes MIME "multipart/form-data" content as specified by RFC 2388: Returning Values from Forms: multipart/form-data

The implementation is a subclass of 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

For a reference on how to build a multipart/form-data request see:

  • http://chxo.com/be2/20050724_93bf.html
  • http://www.faqs.org/rfcs/rfc1867.html

Summary

Constants
String DEFAULT_BOUNDARY
Public Constructors
MultipartFormDataContent()
Creates a new empty MultipartFormDataContent.
Public Methods
MultipartFormDataContent addPart(MultipartContent.Part part)
MultipartFormDataContent addPart(MultipartContent.Part part, String dispositionName, String dispositionFilename)
Adds an HTTP multipart part.
MultipartFormDataContent setBoundary(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(Collection<? extends HttpContent> contentParts)
final MultipartFormDataContent setMediaType(HttpMediaType mediaType)
MultipartFormDataContent setParts(Collection<MultipartContent.Part> parts)
void writeTo(OutputStream out)
Protected Methods
final static HttpMediaType getMultipartFormDataMediaType()
Factory method to create HttpMediaType with media type "multipart/form-data"
[Expand]
Inherited Methods
From class com.google.api.client.http.MultipartContent
From class com.google.api.client.http.AbstractHttpContent
From class java.lang.Object
From interface com.google.api.client.http.HttpContent
From interface com.google.api.client.util.StreamingContent

Constants

protected static final String DEFAULT_BOUNDARY

Constant Value: "__0xKhTmLbOuNdArY__"

Public Constructors

public MultipartFormDataContent ()

Creates a new empty MultipartFormDataContent.

Public Methods

public MultipartFormDataContent addPart (MultipartContent.Part part)

public MultipartFormDataContent addPart (MultipartContent.Part part, String dispositionName, String dispositionFilename)

Adds an HTTP multipart part.

This is a shortcut method to allow adding the specified name and (optional) filename are added in the "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.

Parameters
part The Part to add to the content
dispositionName 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 setBoundary (String boundary)

Sets the boundary string to use (must be not null)

If this is not called, the boundary defaults to DEFAULT_BOUNDARY

Parameters
boundary The new boundary for the content
Throws
NullPointerException if boundary is null

public MultipartFormDataContent setContentParts (Collection<? extends HttpContent> contentParts)

public final MultipartFormDataContent setMediaType (HttpMediaType mediaType)

public MultipartFormDataContent setParts (Collection<MultipartContent.Part> parts)

public void writeTo (OutputStream out)

Throws
IOException

Protected Methods

protected static final HttpMediaType getMultipartFormDataMediaType ()

Factory method to create HttpMediaType with media type "multipart/form-data"