我正在嘗試將文件上傳到存儲桶,解析為 json 并將其插入到 bigquery 中的表中。我收到這個錯誤AttributeError: 'str' object has no attribute 'blob'我認為這是一個依賴問題,但我不知道如何解決。我直接在云函數 GUI 中編碼。def create_gcs(event, context): """Triggered by a change to a Cloud Storage bucket. Args: event (dict): Event payload. context (google.cloud.functions.Context): Metadata for the event. """ file = event print(f"********The file {file['name']} was created in {file['bucket']} at {event['timeCreated']}") bucket = file['bucket'] blob = bucket.get_blob(file['name']) data = blob.download_as_string() table_id="tableid" client=bigquery.Client() client.insert_rows_json(table_id,[data]) print(blob)
1 回答

暮色呼如
TA貢獻1853條經驗 獲得超9個贊
我認為你應該首先創建一個存儲 Client 對象并調用該?get_blob
函數。
斑點/對象
from google.cloud import storage
client = storage.Client()
bucket = client.get_bucket(file['bucket'])
blob = bucket.get_blob(file['name'])
添加回答
舉報
0/150
提交
取消