上传的结构化数据文件成功处理后,使用 media.download 从提供的资源位置下载生成的 ZIP 文件。
以下是检索文件位置并下载 ZIP 文件的方法:
# Import the object used for media download. from googleapiclient import http as googleHttp import io # Provide the name of the successfully completed sdfuploadtask operation. operation_name = operation-name # Provide the path for the output file. output_path = output-path # Retrieve the completed operation. operation = service.sdfuploadtasks().operations().get(operation_name).execute() # Retrieve the file location from the operation. file_location = operation["response"]["resourceName"] # Configure the media.download request. download_request = service.media().download_media(resourceName=file_location) # Create output stream for downloaded file. out_stream = io.FileIO(output_path, mode='wb') # Build downloader object. downloader = googleHttp.MediaIoBaseDownload(out_stream, download_request) # Download file in chunks until finished. download_finished = False while download_finished is False: _, download_finished = downloader.next_chunk() print(f'File downloaded at {output_path}.')
提取文件
解压缩下载的 ZIP 文件,以提取 SDF 上传结果。
可能会出现以下一个或两个结果文件,其中 {EntityName} 是资源类型,例如 LineItems:
SDF-{EntityName}-Updated-ResultFile.csv,其中列出了已成功创建或更新的资源SDF-{EntityName}-Failed-ResultFile.csv,其中列出了未能成功更新或创建的资源以及错误消息。