Package googleapiclient :: Module http :: Class MediaFileUpload
[hide private]
[frames] | no frames]

Class MediaFileUpload

source code


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.

Instance Methods [hide private]
 
__init__(self, filename, mimetype=None, chunksize=DEFAULT_CHUNK_SIZE, resumable=False)
Constructor.
source code
 
to_json(self)
Creating a JSON representation of an instance of MediaFileUpload.
source code

Inherited from MediaIoBaseUpload: chunksize, getbytes, has_stream, mimetype, resumable, size, stream

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

Static Methods [hide private]
 
from_json(s) source code
Properties [hide private]

Inherited from object: __class__

Method Details [hide private]

__init__(self, filename, mimetype=None, chunksize=DEFAULT_CHUNK_SIZE, resumable=False)
(Constructor)

source code 
Constructor.

Args:
  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.

Decorators:
  • @util.positional(2)
Overrides: object.__init__

to_json(self)

source code 
Creating a JSON representation of an instance of MediaFileUpload.

Returns:
   string, a JSON representation of this instance, suitable to pass to
   from_json().

Overrides: MediaUpload.to_json