從 Google Cloud Storage 下載資料到本機檔案系統¶
Google Cloud Storage (GCS) 用於儲存來自各種應用程式的大量資料。本頁說明如何從 GCS 下載資料到本機檔案系統。
先決條件任務¶
若要使用這些運算子,您必須執行以下幾項操作
使用 Cloud Console 選擇或建立 Cloud Platform 專案。
為您的專案啟用計費功能,如 Google Cloud 文件 中所述。
啟用 API,如 Cloud Console 文件 中所述。
透過 pip 安裝 API 函式庫。
pip install 'apache-airflow[google]'如需詳細資訊,請參閱 安裝。
GCSToLocalFilesystemOperator¶
GCSToLocalFilesystemOperator
允許您從 GCS 下載資料到本機檔案系統。
以下是使用此運算子從 GCS 下載檔案的範例。
download_file = GCSToLocalFilesystemOperator(
task_id="download_file",
object_name=FILE_NAME,
bucket=BUCKET_NAME,
filename=PATH_TO_SAVED_FILE,
)