当前位置: 首页>>代码示例>>Python>>正文


Python http.MediaIoBaseUpload方法代码示例

本文整理汇总了Python中apiclient.http.MediaIoBaseUpload方法的典型用法代码示例。如果您正苦于以下问题:Python http.MediaIoBaseUpload方法的具体用法?Python http.MediaIoBaseUpload怎么用?Python http.MediaIoBaseUpload使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在apiclient.http的用法示例。


在下文中一共展示了http.MediaIoBaseUpload方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: save_image

# 需要导入模块: from apiclient import http [as 别名]
# 或者: from apiclient.http import MediaIoBaseUpload [as 别名]
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 
开发者ID:mattbutton,项目名称:google-authentication-with-python-and-flask,代码行数:23,代码来源:google_drive.py

示例2: store_doc

# 需要导入模块: from apiclient import http [as 别名]
# 或者: from apiclient.http import MediaIoBaseUpload [as 别名]
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 
开发者ID:DavidBerdik,项目名称:InfiniDrive,代码行数:18,代码来源:drive_api.py

示例3: insert_object

# 需要导入模块: from apiclient import http [as 别名]
# 或者: from apiclient.http import MediaIoBaseUpload [as 别名]
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() 
开发者ID:google,项目名称:personfinder,代码行数:21,代码来源:cloud_storage.py

示例4: update_fragment

# 需要导入模块: from apiclient import http [as 别名]
# 或者: from apiclient.http import MediaIoBaseUpload [as 别名]
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 
开发者ID:DavidBerdik,项目名称:InfiniDrive,代码行数:17,代码来源:drive_api.py

示例5: _upload

# 需要导入模块: from apiclient import http [as 别名]
# 或者: from apiclient.http import MediaIoBaseUpload [as 别名]
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.') 
开发者ID:google,项目名称:crmint,代码行数:33,代码来源:workers.py


注:本文中的apiclient.http.MediaIoBaseUpload方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。