class documentation

A MediaUpload for a io.Base objects.

Note that the Python file object is compatible with io.Base and can be used with this class also.

fh = BytesIO('...Some data to upload...') media = MediaIoBaseUpload(fh, mimetype='image/png',

chunksize=1024*1024, resumable=True)
farm.animals().insert(
id='cow', name='cow.png', media_body=media).execute()

Depending on the platform you are working on, you may pass -1 as the chunksize, which indicates that the entire file should be uploaded in a single request. If the underlying platform supports streams, such as Python 2.6 or later, then this can be very efficient as it avoids multiple connections, and also avoids loading the entire file into memory before sending it. Note that Google App Engine has a 5MB limit on request size, so you should never set your chunksize larger than 5MB, or to -1.

Method __init__ Constructor.
Method chunksize Chunk size for resumable uploads.
Method getbytes Get bytes from the media.
Method has_stream Does the underlying upload support a streaming interface.
Method mimetype Mime type of the body.
Method resumable Whether this upload is resumable.
Method size Size of upload.
Method stream A stream interface to the data being uploaded.
Method to_json This upload type is not serializable.
Instance Variable _chunksize Undocumented
Instance Variable _fd Undocumented
Instance Variable _mimetype Undocumented
Instance Variable _resumable Undocumented
Instance Variable _size Undocumented

Inherited from MediaUpload:

Class Method new_from_json Utility class method to instantiate a MediaUpload subclass from a JSON representation produced by to_json().
Method _to_json Utility function for creating a JSON representation of a MediaUpload.
@util.positional(3)
def __init__(self, fd, mimetype, chunksize=DEFAULT_CHUNK_SIZE, resumable=False):

Constructor.

Parameters
fdio.Base or file object, The source of the bytes to upload. MUST be opened in blocking mode, do not use streams opened in non-blocking mode. The given stream must be seekable, that is, it must be able to call seek() on fd.
mimetypestring, Mime-type of the file.
chunksizeint, File will be uploaded in chunks of this many bytes. Only used if resumable=True. Pass in a value of -1 if the file is to be uploaded as a single chunk. Note that Google App Engine has a 5MB limit on request size, so you should never set your chunksize larger than 5MB, or to -1.
resumablebool, True if this is a resumable upload. False means upload in a single request.
def chunksize(self):

Chunk size for resumable uploads.

Returns
Chunk size in bytes.
def getbytes(self, begin, length):

Get bytes from the media.

Parameters
beginint, offset from beginning of file.
lengthint, number of bytes to read, starting at begin.
Returns
A string of bytes read. May be shorted than length if EOF was reached first.
def has_stream(self):

Does the underlying upload support a streaming interface.

Streaming means it is an io.IOBase subclass that supports seek, i.e. seekable() returns True.

Returns
True if the call to stream() will return an instance of a seekable io.Base subclass.
def mimetype(self):

Mime type of the body.

Returns
Mime type.
def resumable(self):

Whether this upload is resumable.

Returns
True if resumable upload or False.
def size(self):

Size of upload.

Returns
Size of the body, or None of the size is unknown.
def stream(self):

A stream interface to the data being uploaded.

Returns
The returned value is an io.IOBase subclass that supports seek, i.e. seekable() returns True.
def to_json(self):

This upload type is not serializable.

_chunksize =

Undocumented

_fd =

Undocumented

_mimetype =

Undocumented

_resumable =

Undocumented

_size =

Undocumented