下載結果

上傳的結構化資料檔案處理完成後,請使用 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,其中列出更新或建立失敗的資源,以及錯誤訊息。