class MediaIoBaseUpload(MediaUpload):
Known subclasses: googleapiclient.http.MediaFileUpload, googleapiclient.http.MediaInMemoryUpload
Constructor: MediaIoBaseUpload(fd, mimetype, chunksize, resumable)
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 |
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 |
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 |
Utility class method to instantiate a MediaUpload subclass from a JSON representation produced by to_json(). |
| Method | _to |
Utility function for creating a JSON representation of a MediaUpload. |
def __init__(self, fd, mimetype, chunksize=DEFAULT_CHUNK_SIZE, resumable=False): ¶
Constructor.
| Parameters | |
| 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. |
Get bytes from the media.
| Parameters | |
| 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. | |
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. |
googleapiclient.http.MediaUpload.sizeSize of upload.
| Returns | |
| Size of the body, or None of the size is unknown. |
googleapiclient.http.MediaUpload.streamA stream interface to the data being uploaded.
| Returns | |
| The returned value is an io.IOBase subclass that supports seek, i.e. seekable() returns True. |
googleapiclient.http.MediaUpload.to_jsongoogleapiclient.http.MediaFileUploadThis upload type is not serializable.