將資料從本地檔案系統上傳到 Google Drive¶
Google Drive 用於儲存來自各種應用程式的大量資料。本頁介紹如何將資料從本地檔案系統上傳到 Google Drive。
先決條件任務¶
要使用這些運算子,您必須執行以下幾項操作:
使用 Cloud Console 選擇或建立一個 Cloud Platform 專案。
按照 Google Cloud 文件中的說明,為您的專案啟用結算功能。
按照 Cloud Console 文件中的說明,啟用相應的 API。
透過 pip 安裝 API 庫。
pip install 'apache-airflow[google]'有關 安裝 的詳細資訊。
LocalFilesystemToGoogleDriveOperator¶
LocalFilesystemToGoogleDriveOperator 允許您將資料從本地檔案系統上傳到 Google Drive。
使用此運算子時,您可以上傳檔案列表。
以下是使用此運算子將資料從本地檔案系統上傳到 Google Drive 的示例。
tests/system/google/suite/example_local_to_drive.py
upload_single_file = LocalFilesystemToGoogleDriveOperator(
gcp_conn_id=CONNECTION_ID,
task_id="upload_single_file",
local_paths=SINGLE_FILE_LOCAL_PATHS,
drive_folder=DRIVE_FOLDER,
)