【发布时间】:2019-03-16 17:22:32
【问题描述】:
我是 GCP 的新手,有使用 Python 的经验。 我尝试为一个场景编写一个云函数来解压 GCS 中的文件并将它们复制到另一个存储桶。
from google.cloud import storage
import tarfile
client = storage.Client()
def untar_lookupfiles(data, context):
# Get the file that has been uploaded to GCS
bucket = client.get_bucket(data['Source_bucketName'])
#copy the tarfiles to another bucket
bucket = client.get_bucket('Target_bucketName')
blob = bucket.blob('gs://path/to/file.name')
blob.upload_from_filename('/path/to/source.file')
# Untar the files
print('Untaring Files: {}'.format(data['name']))
untar = tarfile.open("marfiles.tar.gz", "r:gz") # filename is hard coded should be replaced with data['name']
untar.extractall(path=dir)
但看起来这段代码中缺少一些东西,有人可以帮我写代码吗?我没有使用 nodejs 编写代码的经验。感谢您的帮助。
【问题讨论】:
-
你遇到了什么错误?
-
在你用数据填充
tarfiles变量后,我看不到任何地方使用它。你的意思是tarfile? -
@Brandon,我重用了其他东西的代码,现在将其删除,我的要求是将 tar 文件复制到新存储桶中并解压缩它们。
-
现在你没有使用
blob变量来保存get_blob的结果。 -
@BrandonYarbrough,我删除了 get_blob 行,
标签: python google-cloud-platform google-cloud-storage google-cloud-functions