Package apiclient :: Module http :: Class MediaIoBaseUpload |
[hide private]
[frames] | no frames]

# Class MediaIoBaseUpload

source code

    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 = io.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.

Instance Methods | [hide private]
__init__(self, fd, mimetype, chunksize=DEFAULT_CHUNK_SIZE, resumable=False) Constructor. | source code
chunksize(self) Chunk size for resumable uploads. | source code
mimetype(self) Mime type of the body. | source code
size(self) Size of upload. | source code
resumable(self) Whether this upload is resumable. | source code
getbytes(self, begin, length) Get bytes from the media. | source code
has_stream(self) Does the underlying upload support a streaming interface. | source code
stream(self) A stream interface to the data being uploaded. | source code
to_json(self) This upload type is not serializable. | source code
Inherited from `MediaUpload` (private): `_to_json` Inherited from `object`: `__delattr__`, `__format__`, `__getattribute__`, `__hash__`, `__new__`, `__reduce__`, `__reduce_ex__`, `__repr__`, `__setattr__`, `__sizeof__`, `__str__`, `__subclasshook__`

Class Methods | [hide private]
Inherited from `MediaUpload`: `new_from_json`

Properties | [hide private]
Inherited from `object`: `__class__`

Method Details | [hide private]

### __init__(self, fd, mimetype, chunksize=DEFAULT_CHUNK_SIZE, resumable=False) (Constructor) | source code
    Constructor.

    Args:
      fd: io.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.
      mimetype: string, Mime-type of the file.
      chunksize: int, 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.
      resumable: bool, True if this is a resumable upload. False means upload
        in a single request.
Decorators: `@util.positional(3)` Overrides: object.__init__

### chunksize(self) | source code
    Chunk size for resumable uploads.

    Returns:
      Chunk size in bytes.
Overrides: MediaUpload.chunksize

### mimetype(self) | source code
    Mime type of the body.

    Returns:
      Mime type.
Overrides: MediaUpload.mimetype

### size(self) | source code
    Size of upload.

    Returns:
      Size of the body, or None of the size is unknown.
Overrides: MediaUpload.size

### resumable(self) | source code
    Whether this upload is resumable.

    Returns:
      True if resumable upload or False.
Overrides: MediaUpload.resumable

### getbytes(self, begin, length) | source code
    Get bytes from the media.

    Args:
      begin: int, offset from beginning of file.
      length: int, number of bytes to read, starting at begin.

    Returns:
      A string of bytes read. May be shorted than length if EOF was reached
      first.
Overrides: MediaUpload.getbytes

### has_stream(self) | source code
    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.
Overrides: MediaUpload.has_stream

### stream(self) | source code
    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.
Overrides: MediaUpload.stream

### to_json(self) | source code
    This upload type is not serializable.
Overrides: MediaUpload.to_json