【发布时间】:2021-01-22 20:01:54
【问题描述】:
我有几个文件要上传到 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。有任何想法吗?是否可能存在某种权限错误?我怀疑是不是因为我可以创建和下载文件没有问题。我只是无法让 compose 与 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
【问题讨论】:
标签: python google-cloud-functions google-cloud-storage