云功能:从云存储中压缩多个文档

时间:2018-11-22 16:35:48

标签: firebase zip google-cloud-storage google-cloud-functions

我已经搜索了很多关于堆栈溢出的问题,但是找不到合适的答案,我可以从中得出我需要的答案:

我想使用Cloud Function从Google Cloud Storage / Firebase Storage中的文件夹中压缩多个文件。

我已经找到了用于从本地文件系统压缩文档的解决方案,但是无法导出如何在Cloud Cloud Storage功能中进行操作。

1 个答案:

答案 0 :(得分:1)

Google Cloud Storage支持转码的解压缩形式,但不支持转码的压缩形式[1]。但是,在Cloud Storage中,任何用户都可以存储gzip压缩文件。

要使用Cloud Functions从Cloud Storage压缩多个文档,可以使用gcs.bucket.file(filePath).download从Cloud Storage将文件下载到函数实例,下载文件,然后将文件重新上传到Cloud Storage。在这里,您将找到一个下载,转换和上传文件的示例[2]。您可以在此StackOverflow线程[3]中找到压缩多个文件的示例。本文档[4]说明了如何使用控制台,Gsutil,代码示例或REST API将对象上传到Cloud Storage。

[1] https://cloud.google.com/storage/docs/transcoding#transcoding_and_gzip [2] https://firebase.google.com/docs/functions/gcp-storage-events#download_transform_and_upload_a_file [3] how to convert multiple files to compressed zip file using node js [4] https://cloud.google.com/storage/docs/uploading-objects