存储在 GCS 存储桶中时无法重命名文件
Not able to rename the file while storing in GCS bucket
我想在 GCS 中存储文件时重命名文件 bucket.I 参考了此文档:
How to rename a file while storing it to a GCS bucket
它给出了 error.I 不确定我是否修改了它 correfctly.Entry 点是 new_func.This 是下面的代码:
def new_func(event,context):
bucket_name: 'poc_bucket_testing'
blob_name: 'poc_bucket_testing/republic_txttocsv.txt'
new_blob_name: 'target_bucket/republic_txttocsv.csv'
rename_blob(bucket_name,blob_name,new_blob_name);
def rename_blob(bucket_name,blob_name,new_blob_name):
print("inside");
bucket = storage_client.bucket(bucket_name)
blob = bucket.blob(blob_name)
new_blob = bucket.rename_blob(blob,new_blob_name)
return new_blob.public_url
给出错误 below.I 也尝试在 rename_blob 中分配它并给出相同的错误。
"Traceback (most recent call last):
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 38, in new_func
rename_blob(bucket_name,blob_name,new_blob_name);
UnboundLocalError: local variable 'bucket_name' referenced before assignment
您正在使用冒号(如在字典中)而不是赋值运算符:
def new_func(event,context):
bucket_name = 'poc_bucket_testing'
blob_name = 'poc_bucket_testing/republic_txttocsv.txt'
new_blob_name = 'target_bucket/republic_txttocsv.csv'
rename_blob(bucket_name,blob_name,new_blob_name)
我想在 GCS 中存储文件时重命名文件 bucket.I 参考了此文档:
How to rename a file while storing it to a GCS bucket
它给出了 error.I 不确定我是否修改了它 correfctly.Entry 点是 new_func.This 是下面的代码:
def new_func(event,context):
bucket_name: 'poc_bucket_testing'
blob_name: 'poc_bucket_testing/republic_txttocsv.txt'
new_blob_name: 'target_bucket/republic_txttocsv.csv'
rename_blob(bucket_name,blob_name,new_blob_name);
def rename_blob(bucket_name,blob_name,new_blob_name):
print("inside");
bucket = storage_client.bucket(bucket_name)
blob = bucket.blob(blob_name)
new_blob = bucket.rename_blob(blob,new_blob_name)
return new_blob.public_url
给出错误 below.I 也尝试在 rename_blob 中分配它并给出相同的错误。
"Traceback (most recent call last):
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 38, in new_func
rename_blob(bucket_name,blob_name,new_blob_name);
UnboundLocalError: local variable 'bucket_name' referenced before assignment
您正在使用冒号(如在字典中)而不是赋值运算符:
def new_func(event,context):
bucket_name = 'poc_bucket_testing'
blob_name = 'poc_bucket_testing/republic_txttocsv.txt'
new_blob_name = 'target_bucket/republic_txttocsv.csv'
rename_blob(bucket_name,blob_name,new_blob_name)