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()

Instance Methods [hide private]
 
__init__(self, fd, mimetype, chunksize=524288, 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
 
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=524288, 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.
  mimetype: string, Mime-type of the file. If None then a mime-type will be
    guessed from the file extension.
  chunksize: int, File will be uploaded in chunks of this many bytes. Only
    used if resumable=True.
  resumable: bool, True if this is a resumable upload. False means upload
    in a single request.

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

to_json(self)

source code 
This upload type is not serializable.

Overrides: MediaUpload.to_json