谷歌云函数python无法与blob交互

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


慕村9548890
浏览 83回答 1
1回答

暮色呼如

我认为你应该首先创建一个存储 Client 对象并调用该 get_blob函数。斑点/对象from google.cloud import storageclient = storage.Client()bucket = client.get_bucket(file['bucket'])blob = bucket.get_blob(file['name'])
打开App,查看更多内容
随时随地看视频慕课网APP

相关分类

Python