當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。