class documentation

class MediaUpload(object):

Known subclasses: googleapiclient.http.MediaIoBaseUpload

View In Hierarchy

Describes a media object to upload.

Base class that defines the interface of MediaUpload subclasses.

Note that subclasses of MediaUpload may allow you to control the chunksize when uploading a media object. It is important to keep the size of the chunk as large as possible to keep the upload efficient. Other factors may influence the size of the chunk you use, particularly if you are working in an environment where individual HTTP requests may have a hardcoded time limit, such as under certain classes of requests under Google App Engine.

Streams are io.Base compatible objects that support seek(). Some MediaUpload subclasses support using streams directly to upload data. Support for streaming may be indicated by a MediaUpload sub-class and if appropriate for a platform that stream will be used for uploading the media object. The support for streaming is indicated by has_stream() returning True. The stream() method should return an io.Base object that supports seek(). On platforms where the underlying httplib module supports streaming, for example Python 2.6 and later, the stream will be passed into the http library which will result in less memory being used and possibly faster uploads.

If you need to upload media that can't be uploaded using any of the existing MediaUpload sub-class then you can sub-class MediaUpload for your particular needs.

Class Method new_from_json Utility class method to instantiate a MediaUpload subclass from a JSON representation produced by to_json().
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 Create a JSON representation of an instance of MediaUpload.
Method _to_json Utility function for creating a JSON representation of a MediaUpload.
@classmethod
def new_from_json(cls, s):

Utility class method to instantiate a MediaUpload subclass from a JSON representation produced by to_json().

Parameters
sstring, JSON from to_json().
Returns
An instance of the subclass of MediaUpload that was serialized with to_json().
def chunksize(self):

Chunk size for resumable uploads.

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

Get bytes from the media.

Parameters
beginint, offset from beginning of file.
endUndocumented
lengthint, number of bytes to read, starting at begin.
Returns
A string of bytes read. May be shorter 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):

Create a JSON representation of an instance of MediaUpload.

Returns
string, a JSON representation of this instance, suitable to pass to from_json().
@util.positional(1)
def _to_json(self, strip=None):

Utility function for creating a JSON representation of a MediaUpload.

Parameters
striparray, An array of names of members to not include in the JSON.
Returns
string, a JSON representation of this instance, suitable to pass to from_json().