我正在嘗試將文件上傳到存儲(chǔ)桶,解析為 json 并將其插入到 bigquery 中的表中。我收到這個(gè)錯(cuò)誤AttributeError: 'str' object has no attribute 'blob'我認(rèn)為這是一個(gè)依賴(lài)問(wèn)題,但我不知道如何解決。我直接在云函數(shù) 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貢獻(xiàn)1853條經(jīng)驗(yàn) 獲得超9個(gè)贊
我認(rèn)為你應(yīng)該首先創(chuàng)建一個(gè)存儲(chǔ) Client 對(duì)象并調(diào)用該?get_blob
函數(shù)。
斑點(diǎn)/對(duì)象
from google.cloud import storage
client = storage.Client()
bucket = client.get_bucket(file['bucket'])
blob = bucket.get_blob(file['name'])
添加回答
舉報(bào)
0/150
提交
取消