小编Rak*_*007的帖子

python 谷歌云函数解压文件

我是 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)
Run Code Online (Sandbox Code Playgroud)

但是这段代码中似乎缺少某些东西,有人可以帮我编写代码吗?我没有使用 nodejs 编写代码的经验。感谢你的帮助。

python google-cloud-storage google-cloud-platform google-cloud-functions

3
推荐指数
1
解决办法
1916
查看次数