我正在尝试将文件上传到存储桶,解析为 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
提交
取消