![](/img/trans.png)
[英]How does paging work in the list_blobs function in Google Cloud Storage Python Client Library
[英]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.