首页 > 解决方案 > google cloud platform blob.download_to_file 文件下载位置

问题描述

gcloud beta functions deploy gcp-data-transfer --project probable-scout-216702 --runtime python37 --trigger-bucket connector-test-data-securonix --entry-point detect_file

以上是我正在使用的谷歌云功能。这是我的谷歌云存储桶上的触发器。我的 gcloud 功能正在运行,但我不知道文件应该下载到哪里。我能够将它存储在一个/tmp/目录中,但它仍然不在我自己的系统上,我不知道/tmp它正在下载哪个。我是使用以下代码:

def detect_file(file, context):
    destination_file_name = "/Securonix/file1.txt"
    f = open("/Securonix/file1.txt",'wb')
    bucket = validate_message(file, 'bucket')
    name = validate_message(file, 'name')
    print("here")
    storage_client = storage.Client()
    bucket = storage_client.get_bucket(bucket)
    blob = bucket.blob(name)
    blob.download_to_file(f)
    print('Blob {} downloaded to {}.'.format(
        name,
        destination_file_name))


def validate_message(message, param):
    var = message.get(param)
    if not var:
        raise ValueError('{} is not provided. Make sure you have \
                          property {} in the request'.format(param, param))
    return var

我收到错误:

FileNotFoundError: [Errno 2] No such file or directory: '/Securonix/file1.txt'

标签: google-cloud-platformblobgoogle-cloud-storagegoogle-cloud-functions

解决方案


然后使用/tmp/您的文件名,这是因为您无法在除/tmp/文件夹之外的云功能上创建文件。

你的字符串是这样的:

/tmp/Securonix/file1.txt

推荐阅读