(self, http=None)
return self._process_response(resp, content)
Execute the next step of a resumable upload.

    Can only be used if the method being executed supports media uploads and
    the MediaUpload object passed in was flagged as using resumable upload.

    Example:

      media = MediaFileUpload('cow.png', mimetype='image/png',
                              chunksize=1000, resumable=True)
      request = farm.animals().insert(
          id='cow',
          name='cow.png',
          media_body=media)

      response = None
      while response is None:
        status, response = request.next_chunk()
        if status:
          print "Upload %d%% complete." % int(status.progress() * 100)


    Returns:
      (status, body): (ResumableMediaStatus, object)
         The body will be None until the resumable media is fully uploaded.

    Raises:
      apiclient.errors.HttpError if the response was not a 2xx.
      httplib2.HttpLib2Error if a transport error has occured.
Execute the next step of a resumable upload.
Execute the next step of a resumable upload .
def next_chunk(self, http=None):
    """Execute the next step of a resumable upload.

    Can only be used if the method being executed supports media uploads and
    the MediaUpload object passed in was flagged as using resumable upload.

    Example:

      media = MediaFileUpload('cow.png', mimetype='image/png',
                              chunksize=1000, resumable=True)
      request = farm.animals().insert(
          id='cow',
          name='cow.png',
          media_body=media)

      response = None
      while response is None:
        status, response = request.next_chunk()
        if status:
          print "Upload %d%% complete." % int(status.progress() * 100)


    Returns:
      (status, body): (ResumableMediaStatus, object)
         The body will be None until the resumable media is fully uploaded.

    Raises:
      apiclient.errors.HttpError if the response was not a 2xx.
      httplib2.HttpLib2Error if a transport error has occured.
    """
    if http is None:
      http = self.http

    if self.resumable.size() is None:
      size = '*'
    else:
      size = str(self.resumable.size())

    if self.resumable_uri is None:
      start_headers = copy.copy(self.headers)
      start_headers['X-Upload-Content-Type'] = self.resumable.mimetype()
      if size != '*':
        start_headers['X-Upload-Content-Length'] = size
      start_headers['content-length'] = str(self.body_size)

      resp, content = http.request(self.uri, self.method,
                                   body=self.body,
                                   headers=start_headers)
      if resp.status == 200 and 'location' in resp:
        self.resumable_uri = resp['location']
      else:
        raise ResumableUploadError(resp, content)
    elif self._in_error_state:
      # If we are in an error state then query the server for current state of
      # the upload by sending an empty PUT and reading the 'range' header in
      # the response.
      headers = {
          'Content-Range': 'bytes */%s' % size,
          'content-length': '0'
          }
      resp, content = http.request(self.resumable_uri, 'PUT',
                                   headers=headers)
      status, body = self._process_response(resp, content)
      if body:
        # The upload was complete.
        return (status, body)

    # The httplib.request method can take streams for the body parameter, but
    # only in Python 2.6 or later. If a stream is available under those
    # conditions then use it as the body argument.
    if self.resumable.has_stream() and sys.version_info[1] >= 6:
      data = self.resumable.stream()
      if self.resumable.chunksize() == -1:
        data.seek(self.resumable_progress)
        chunk_end = self.resumable.size() - self.resumable_progress - 1
      else:
        # Doing chunking with a stream, so wrap a slice of the stream.
        data = _StreamSlice(data, self.resumable_progress,
                            self.resumable.chunksize())
        chunk_end = min(
            self.resumable_progress + self.resumable.chunksize() - 1,
            self.resumable.size() - 1)
    else:
      data = self.resumable.getbytes(
          self.resumable_progress, self.resumable.chunksize())

      # A short read implies that we are at EOF, so finish the upload.
      if len(data) < self.resumable.chunksize():
        size = str(self.resumable_progress + len(data))

      chunk_end = self.resumable_progress + len(data) - 1

    headers = {
        'Content-Range': 'bytes %d-%d/%s' % (
            self.resumable_progress, chunk_end, size),
        # Must set the content-length header here because httplib can't
        # calculate the size when working with _StreamSlice.
        'Content-Length': str(chunk_end - self.resumable_progress + 1)
        }
    try:
      resp, content = http.request(self.resumable_uri, 'PUT',
                                   body=data,
                                   headers=headers)
    except:
      self._in_error_state = True
      raise

    return self._process_response(resp, content)
def next_chunk ( self , http = None ) : if http is None : http = self . http if self . resumable . size ( ) is None : size = '*' else : size = str ( self . resumable . size ( ) ) if self . resumable_uri is None : start_headers = copy . copy ( self . headers ) start_headers [ 'X-Upload-Content-Type' ] = self . resumable . mimetype ( ) if size != '*' : start_headers [ 'X-Upload-Content-Length' ] = size start_headers [ 'content-length' ] = str ( self . body_size ) resp , content = http . request ( self . uri , self . method , body = self . body , headers = start_headers ) if resp . status == 200 and 'location' in resp : self . resumable_uri = resp [ 'location' ] else : raise ResumableUploadError ( resp , content ) elif self . _in_error_state : # If we are in an error state then query the server for current state of # the upload by sending an empty PUT and reading the 'range' header in # the response. headers = { 'Content-Range' : 'bytes */%s' % size , 'content-length' : '0' } resp , content = http . request ( self . resumable_uri , 'PUT' , headers = headers ) status , body = self . _process_response ( resp , content ) if body : # The upload was complete. return ( status , body ) # The httplib.request method can take streams for the body parameter, but # only in Python 2.6 or later. If a stream is available under those # conditions then use it as the body argument. if self . resumable . has_stream ( ) and sys . version_info [ 1 ] >= 6 : data = self . resumable . stream ( ) if self . resumable . chunksize ( ) == - 1 : data . seek ( self . resumable_progress ) chunk_end = self . resumable . size ( ) - self . resumable_progress - 1 else : # Doing chunking with a stream, so wrap a slice of the stream. data = _StreamSlice ( data , self . resumable_progress , self . resumable . chunksize ( ) ) chunk_end = min ( self . resumable_progress + self . resumable . chunksize ( ) - 1 , self . resumable . size ( ) - 1 ) else : data = self . resumable . getbytes ( self . resumable_progress , self . resumable . chunksize ( ) ) # A short read implies that we are at EOF, so finish the upload. if len ( data ) < self . resumable . chunksize ( ) : size = str ( self . resumable_progress + len ( data ) ) chunk_end = self . resumable_progress + len ( data ) - 1 headers = { 'Content-Range' : 'bytes %d-%d/%s' % ( self . resumable_progress , chunk_end , size ) , # Must set the content-length header here because httplib can't # calculate the size when working with _StreamSlice. 'Content-Length' : str ( chunk_end - self . resumable_progress + 1 ) } try : resp , content = http . request ( self . resumable_uri , 'PUT' , body = data , headers = headers ) except : self . _in_error_state = True raise return self . _process_response ( resp , content )