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


Python http.MediaIoBaseDownload方法代码示例

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


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

示例1: _download

# 需要导入模块: from apiclient import http [as 别名]
# 或者: from apiclient.http import MediaIoBaseDownload [as 别名]
def _download(self, filename=None, _fileType="spreadsheet"):
        fileTypes = {
            "csv": "text/csv",
            "xlsx": "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet",
            "ods": "application/x-vnd.oasis.opendocument.spreadsheet",
            "pdf": "application/pdf",
            "zip": "application/zip",  # a zip file of html files
            "tsv": "text/tab-separated-values",
        }

        if filename is None:
            filename = _makeFilenameSafe(self._title) + "." + _fileType

        request = DRIVE_SERVICE.files().export_media(fileId=self._spreadsheetId, mimeType=fileTypes[_fileType])
        fh = open(filename, "wb")
        downloader = MediaIoBaseDownload(fh, request)
        done = False
        while done is False:
            status, done = downloader.next_chunk()

        return filename 
开发者ID:asweigart,项目名称:ezsheets,代码行数:23,代码来源:__init__.py

示例2: view_file

# 需要导入模块: from apiclient import http [as 别名]
# 或者: from apiclient.http import MediaIoBaseDownload [as 别名]
def view_file(file_id):
    drive_api = build_drive_api_v3()

    metadata = drive_api.get(fields="name,mimeType", fileId=file_id).execute()

    request = drive_api.get_media(fileId=file_id)
    fh = io.BytesIO()
    downloader = MediaIoBaseDownload(fh, request)

    done = False
    while done is False:
        status, done = downloader.next_chunk()

    fh.seek(0)

    return flask.send_file(
                     fh,
                     attachment_filename=metadata['name'],
                     mimetype=metadata['mimeType']
               ) 
开发者ID:mattbutton,项目名称:google-authentication-with-python-and-flask,代码行数:22,代码来源:google_drive.py

示例3: download_file

# 需要导入模块: from apiclient import http [as 别名]
# 或者: from apiclient.http import MediaIoBaseDownload [as 别名]
def download_file(service, file_id, location, filename):
    request = service.files().get_media(fileId=file_id)
    fh = io.FileIO('{}{}'.format(location, filename), 'wb')
    downloader = MediaIoBaseDownload(fh, request,chunksize=1024*1024)
    done = False
    while done is False:
        status, done = downloader.next_chunk()
        if status:
            #print '\rDownload {}%.'.format(int(status.progress() * 100)),
            print int(status.progress() * 100)," percent complete         \r",
            #sys.stdout.flush()
    print ""
    print colored(('%s downloaded!' % filename), 'green') 
开发者ID:duytran1406,项目名称:gdrivedownloader,代码行数:15,代码来源:download.py

示例4: download_file

# 需要导入模块: from apiclient import http [as 别名]
# 或者: from apiclient.http import MediaIoBaseDownload [as 别名]
def download_file(self, file_name, file_id):
        request = self._service.files().get_media(fileId=file_id)
        fh = io.FileIO(file_name, 'wb')
        downloader = MediaIoBaseDownload(fh, request)
        done = False
        while done is False:
            status, done = downloader.next_chunk()
            logger.debug("Download %d%%." % int(status.progress() * 100)) 
开发者ID:luk6xff,项目名称:Packt-Publishing-Free-Learning,代码行数:10,代码来源:google_drive.py

示例5: retrieve_content

# 需要导入模块: from apiclient import http [as 别名]
# 或者: from apiclient.http import MediaIoBaseDownload [as 别名]
def retrieve_content(
      self, context, bucket, path, transform=None, generation=None, **kwargs):
    """Retrieves the content at the specified path.

    Args:
      bucket: [string] The bucket to retrieve front.
      path: [string] The path to the content to retrieve from the bucket.
      generation: [long] Specifies version of object (or None for current).
      transform: [callable(string)] transform the downloaded bytes into
         something else (e.g. a JSON object). If None then the identity.

    Returns:
      transformed object.
    """
    self.logger.info('Retrieving path=%s from bucket=%s [generation=%s]',
                     path, bucket, generation)

    # Get Payload Data
    bucket = context.eval(bucket)
    path = context.eval(path)
    generation = context.eval(generation)
    request = self.service.objects().get_media(
        bucket=bucket,
        object=path,
        generation=generation,
        **kwargs)

    data = io.BytesIO()
    downloader = MediaIoBaseDownload(data, request, chunksize=1024*1024)
    done = False
    while not done:
      status, done = downloader.next_chunk()
      if status:
        self.logger.debug('Download %d%%', int(status.progress() * 100))

    result = bytes.decode(data.getvalue())
    return result if transform is None else transform(result) 
开发者ID:google,项目名称:citest,代码行数:39,代码来源:gcp_storage_agent.py

示例6: download_file_as

# 需要导入模块: from apiclient import http [as 别名]
# 或者: from apiclient.http import MediaIoBaseDownload [as 别名]
def download_file_as(service, file_id, media_type, file_name):
    request = service.files().export_media(fileId=file_id, mimeType=media_type)
    fh = io.FileIO(file_name, mode='wb')
    downloader = MediaIoBaseDownload(fh, request)
    done = False
    while done is False:
        status, done = downloader.next_chunk()
        print("Download %d%%." % int(status.progress() * 100)) 
开发者ID:ftomassetti,项目名称:DriveInvoicing,代码行数:10,代码来源:main.py

示例7: get_image_bytes_from_doc

# 需要导入模块: from apiclient import http [as 别名]
# 或者: from apiclient.http import MediaIoBaseDownload [as 别名]
def get_image_bytes_from_doc(service, file):
	# Download file to memory
	request = service.files().export_media(fileId=file['id'], mimeType='application/vnd.openxmlformats-officedocument.wordprocessingml.document')
	fh = BytesIO()
	downloader = MediaIoBaseDownload(fh, request)
	done = False
	while done is False:
		status, done = downloader.next_chunk()

	# Extract image from file and return the image's bytes
	zipRef = zipfile.ZipFile(fh, 'r')
	imgBytes = zipRef.read('word/media/image1.png')
	zipRef.close()
	return BytesIO(imgBytes) 
开发者ID:DavidBerdik,项目名称:InfiniDrive,代码行数:16,代码来源:drive_api.py


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