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',
(self, http=None, num_retries=0)
| 952 | |
| 953 | @util.positional(1) |
| 954 | def next_chunk(self, http=None, num_retries=0): |
| 955 | """Execute the next step of a resumable upload. |
| 956 | |
| 957 | Can only be used if the method being executed supports media uploads and |
| 958 | the MediaUpload object passed in was flagged as using resumable upload. |
| 959 | |
| 960 | Example: |
| 961 | |
| 962 | media = MediaFileUpload('cow.png', mimetype='image/png', |
| 963 | chunksize=1000, resumable=True) |
| 964 | request = farm.animals().insert( |
| 965 | id='cow', |
| 966 | name='cow.png', |
| 967 | media_body=media) |
| 968 | |
| 969 | response = None |
| 970 | while response is None: |
| 971 | status, response = request.next_chunk() |
| 972 | if status: |
| 973 | print "Upload %d%% complete." % int(status.progress() * 100) |
| 974 | |
| 975 | |
| 976 | Args: |
| 977 | http: httplib2.Http, an http object to be used in place of the |
| 978 | one the HttpRequest request object was constructed with. |
| 979 | num_retries: Integer, number of times to retry with randomized |
| 980 | exponential backoff. If all retries fail, the raised HttpError |
| 981 | represents the last request. If zero (default), we attempt the |
| 982 | request only once. |
| 983 | |
| 984 | Returns: |
| 985 | (status, body): (ResumableMediaStatus, object) |
| 986 | The body will be None until the resumable media is fully uploaded. |
| 987 | |
| 988 | Raises: |
| 989 | googleapiclient.errors.HttpError if the response was not a 2xx. |
| 990 | httplib2.HttpLib2Error if a transport error has occurred. |
| 991 | """ |
| 992 | if http is None: |
| 993 | http = self.http |
| 994 | |
| 995 | if self.resumable.size() is None: |
| 996 | size = "*" |
| 997 | else: |
| 998 | size = str(self.resumable.size()) |
| 999 | |
| 1000 | if self.resumable_uri is None: |
| 1001 | start_headers = copy.copy(self.headers) |
| 1002 | start_headers["X-Upload-Content-Type"] = self.resumable.mimetype() |
| 1003 | if size != "*": |
| 1004 | start_headers["X-Upload-Content-Length"] = size |
| 1005 | start_headers["content-length"] = str(self.body_size) |
| 1006 | |
| 1007 | resp, content = _retry_request( |
| 1008 | http, |
| 1009 | num_retries, |
| 1010 | "resumable URI request", |
| 1011 | self._sleep, |