我在 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 存储桶内的文件夹
发布评论