class MediaFileUpload(MediaIoBaseUpload):
Constructor: MediaFileUpload(filename, mimetype, chunksize, resumable)
A MediaUpload for a file.
Construct a MediaFileUpload and pass as the media_body parameter of the method. For example, if we had a service that allowed uploading images:
- media = MediaFileUpload('cow.png', 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.
| Static Method | from |
Undocumented |
| Method | __del__ |
Undocumented |
| Method | __init__ |
Constructor. |
| Method | to |
Creating a JSON representation of an instance of MediaFileUpload. |
| Instance Variable | _fd |
Undocumented |
| Instance Variable | _filename |
Undocumented |
Inherited from MediaIoBaseUpload:
| 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. |
| Instance Variable | _chunksize |
Undocumented |
| Instance Variable | _mimetype |
Undocumented |
| Instance Variable | _resumable |
Undocumented |
| Instance Variable | _size |
Undocumented |
Inherited from MediaUpload (via MediaIoBaseUpload):
| 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, filename, mimetype=None, chunksize=DEFAULT_CHUNK_SIZE, resumable=False): ¶
Constructor.
| Parameters | |
| filename | string, Name of the file. |
| 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. Pass in a value of -1 if the file is to be uploaded in 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. |