簡體   English   中英

谷歌雲 function python 無法與 blob 交互

[英]Google cloud function python cannot interact with blobs

我正在嘗試將文件上傳到存儲桶,解析為 json 並將其插入到 bigquery 中的表中。 我收到這個錯誤

AttributeError: 'str' object has no attribute 'blob'

我相信這是一個依賴問題,但我不知道如何解決。

我正在直接編碼到雲 function 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)

我認為你應該首先創建一個存儲客戶端 object 並調用get_blob function。

斑點/對象

from google.cloud import storage
client = storage.Client()
bucket = client.get_bucket(file['bucket'])
blob = bucket.get_blob(file['name'])

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM