微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

在 Google Cloud Function 中使用 compose for Google Cloud Storage 时出现 404 错误

如何解决在 Google Cloud Function 中使用 compose for Google Cloud Storage 时出现 404 错误

我有几个文件上传到 Google Cloud Storage,然后使用 compose 合并。我可以上传文件,但无法组合工作。我最初用 Nodejs 尝试过,但遇到了奇怪的错误,现在尝试在用 Python 编写的云函数中使用 compose。这是我正在使用的代码

from google.cloud import storage

def compose_file(event,context):
    bucket_name = 'bucket-name-appspot.com'
    storage_client = storage.Client()
    bucket = storage_client.bucket(bucket_name)

    blob1 = bucket.blob('composettest/compose1.txt')
    blob2 = bucket.blob('composettest/compose2.txt')

    sources = [blob1,blob2]
    destination_blob_name = 'compose3.txt'
    print(blob1)
    print(blob2)

    destination = bucket.blob(destination_blob_name)
    print(destination)
    destination.content_type = "text/plain"
    destination.compose(sources)
    return destination

这是我不断收到的错误。我知道该文件存在,因为我可以将其打印为 blob。有任何想法吗?是否可能存在某种权限错误?我怀疑是因为我可以创建和下载文件没问题。我只是无法组合使用 python 或 nodejs 客户端库。

  File "/env/local/lib/python3.7/site-packages/google/cloud/functions/worker_v2.py",line 449,in run_background_function
    _function_handler.invoke_user_function(event_object)
  File "/env/local/lib/python3.7/site-packages/google/cloud/functions/worker_v2.py",line 268,in invoke_user_function
    return call_user_function(request_or_event)
  File "/env/local/lib/python3.7/site-packages/google/cloud/functions/worker_v2.py",line 265,in call_user_function
    event_context.Context(**request_or_event.context))
  File "/user_code/main.py",line 26,in compose_file
    destination.compose(sources)
  File "/env/local/lib/python3.7/site-packages/google/cloud/storage/blob.py",line 3070,in compose
    retry=retry,File "/env/local/lib/python3.7/site-packages/google/cloud/storage/_http.py",line 63,in api_request
    return call()
  File "/env/local/lib/python3.7/site-packages/google/cloud/_http.py",line 438,in api_request
    raise exceptions.from_http_response(response)
google.api_core.exceptions.NotFound: 404 POST https://storage.googleapis.com/storage/v1/b/bucket-name-appspot.com/o/compose3.txt/compose?prettyPrint=false: Not Found

解决方法

您无法在新文件中进行创作。你拿了一个文件,然后和另一个文件组合起来。在您的情况下,您要么首先在 GCS 中创建一个空的 compose3.txt,然后您就可以创建您的命令。或者,您使用 compose1 作为目标,仅使用 compose2 作为源,并且两者组合在一起。

,

您似乎指定了一个不存在的存储分区:

% gsutil ls gs://bucket-name-appspot.com
BucketNotFoundException: 404 gs://bucket-name-appspot.com bucket does not exist.

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。