云功能将所有文件从存储桶复制到同一 GCS 存储桶内的文件夹

编程入门 行业动态 更新时间:2024-10-09 16:28:56
本文介绍了云功能将所有文件从存储桶复制到同一 GCS 存储桶内的文件夹的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

我在 Google Cloud Storage 存储桶中有文件,我想从存储桶中复制收到的所有文件,并在同一个存储桶的文件夹中创建所有这些文件的副本.(我找到了复制到存储桶的解决方案,但如何复制到存储桶内的文件夹?)

I have files inside a Google Cloud Storage bucket, I want to copy all the files from the bucket as received and create a copy of all those files inside a folder in the same bucket. (I found solution to copy to a bucket, but how to copy to a FOLDER inside a bucket?)

destination = storage_client.bucket('source-bucket-name') #here my source &目标桶相同

destination = storage_client.bucket('source-bucket-name') #here my source & destination bucket is same

有没有办法将文件夹名称与存储桶名称一起传递?

Is there a way to pass the folder name along with the bucket name?

推荐答案

实际上 Google Cloud Storage 没有真正的文件夹".在 Cloud Storage 控制台中,存储桶中的文件以文件夹的分层树状结构呈现(就像本地硬盘上的文件系统一样),但这只是呈现文件的一种方式:没有真正的文件夹/目录在一个桶里.Cloud Storage 控制台仅使用文件路径的不同部分来模拟"文件路径.文件夹结构,通过使用/"分隔符.

Actually Google Cloud Storage does not have genuine "folders". In the Cloud Storage console, the files in your bucket are presented in a hierarchical tree of folders (just like the file system on your local hard disk) but this is just a way of presenting the files: there aren't genuine folders/directories in a bucket. The Cloud Storage console just uses the different parts of the file paths to "simulate" a folder structure, by using the "/" delimiter character.

这个关于 Cloud Storage 和 gsutil 的doc 解释和说明了非常好吧,这就是分层文件树的错觉".

This doc on Cloud Storage and gsutil explains and illustrates very well this "illusion of a hierarchical file tree".

因此,换句话说,您可以使用由文件夹/目录"组成的文件名(或文件路径).名称,然后是/"分隔符,最后是文件名.例如:fileName = "summer1970/pic1234.jpg".正如下面的评论所阐明的,分层文件树的错觉是通过文件命名而不是通过存储桶命名创建的.

So, in other words, it's up to you to use a file name (or file path) that is composed by the "folder/directory" name, then the "/" delimiter character and finally the file name. E.g.: fileName = "summer1970/pic1234.jpg". As clarified in the comments below, the illusion of a hierarchical file tree is created via the files naming not via the bucket naming.

更多推荐

云功能将所有文件从存储桶复制到同一 GCS 存储桶内的文件夹

本文发布于:2023-11-24 14:03:26,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1625512.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:文件夹   功能   文件   GCS

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!