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