Python apiclient.http.MediaIoBaseUpload() Examples
The following are 5
code examples of apiclient.http.MediaIoBaseUpload().
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example.
You may also want to check out all available functions/classes of the module
apiclient.http
, or try the search function
.
Example #1
Source File: google_drive.py From google-authentication-with-python-and-flask with MIT License | 6 votes |
def save_image(file_name, mime_type, file_data): drive_api = build_drive_api_v3() generate_ids_result = drive_api.generateIds(count=1).execute() file_id = generate_ids_result['ids'][0] body = { 'id': file_id, 'name': file_name, 'mimeType': mime_type, } media_body = MediaIoBaseUpload(file_data, mimetype=mime_type, resumable=True) drive_api.create(body=body, media_body=media_body, fields='id,name,mimeType,createdTime,modifiedTime').execute() return file_id
Example #2
Source File: drive_api.py From InfiniDrive with GNU General Public License v3.0 | 6 votes |
def store_doc(service, folderId, file_name, crc32, sha256, file_path): file_metadata = { 'name': file_name, 'mimeType': 'application/vnd.google-apps.document', 'parents': [folderId], 'properties': { 'crc32': str(crc32), 'sha256': str(sha256) } } media = MediaIoBaseUpload(file_path, mimetype='application/vnd.openxmlformats-officedocument.wordprocessingml.document') service.files().create(body=file_metadata, media_body=media, fields = 'id').execute() # Updates a given fragment
Example #3
Source File: cloud_storage.py From personfinder with Apache License 2.0 | 6 votes |
def insert_object(self, object_name, content_type, data): """Uploads an object to the bucket. Args: object_name (str): Name of the object. content_type (str): MIME type string of the object. data (str): The content of the object. """ media = MediaIoBaseUpload(StringIO.StringIO(data), mimetype=content_type) self.service.objects().insert( bucket=self.bucket_name, name=object_name, body={ # This let browsers to download the file instead of opening # it in a browser. 'contentDisposition': 'attachment; filename=%s' % object_name, }, media_body=media).execute()
Example #4
Source File: drive_api.py From InfiniDrive with GNU General Public License v3.0 | 5 votes |
def update_fragment(service, frag_id, crc32, sha256, file_path): media = MediaIoBaseUpload(file_path, mimetype='application/vnd.openxmlformats-officedocument.wordprocessingml.document') file_metadata = { 'properties': { 'crc32': str(crc32), 'sha256': str(sha256) } } service.files().update( fileId=frag_id, body=file_metadata, media_body=media, fields='id').execute() #Returns folder id and service object for document insertion into the folder
Example #5
Source File: workers.py From crmint with Apache License 2.0 | 5 votes |
def _upload(self): with gcs.open(self._file_name, read_buffer_size=self._BUFFER_SIZE) as f: media = MediaIoBaseUpload(f, mimetype='application/octet-stream', chunksize=self._BUFFER_SIZE, resumable=True) request = self._ga_client.management().uploads().uploadData( accountId=self._account_id, webPropertyId=self._params['property_id'], customDataSourceId=self._params['dataset_id'], media_body=media) response = None tries = 0 milestone = 0 while response is None and tries < 5: try: status, response = request.next_chunk() except HttpError, e: if e.resp.status in [404, 500, 502, 503, 504]: tries += 1 delay = 5 * 2 ** (tries + random()) self.log_warn('%s, Retrying in %.1f seconds...', e, delay) time.sleep(delay) else: raise WorkerException(e) else: tries = 0 if status: progress = int(status.progress() * 100) if progress >= milestone: self.log_info('Uploaded %d%%.', int(status.progress() * 100)) milestone += 20 self.log_info('Upload Complete.')