亚洲在线久爱草,狠狠天天香蕉网,天天搞日日干久草,伊人亚洲日本欧美

為了賬號安全,請及時綁定郵箱和手機立即綁定
已解決430363個問題,去搜搜看,總會有你想問的

谷歌云函數python無法與blob交互

谷歌云函數python無法與blob交互

慕村9548890 2023-10-26 15:40:02
我正在嘗試將文件上傳到存儲桶,解析為 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'])


查看完整回答
反對 回復 2023-10-26
  • 1 回答
  • 0 關注
  • 216 瀏覽
慕課專欄
更多

添加回答

舉報

0/150
提交
取消
微信客服

購課補貼
聯系客服咨詢優惠詳情

幫助反饋 APP下載

慕課網APP
您的移動學習伙伴

公眾號

掃描二維碼
關注慕課網微信公眾號