如何在保留文件夹而不删除它们的同时移动 S3 存储桶中的文件?
How do I move files in a S3 bucket while keeping the folders and not deleting them?
在S3中,我有一个只有1个文件的文件夹A。
我想将该文件移动到文件夹 B,如将文件从 A 复制到 B,然后将其从 A 中删除。
但是CDK在删除文件的同时也删除了A文件夹。我想保留这两个文件夹。
为什么要删除文件夹?如何告诉 CDK 不要删除?
虽然您在 AWS 控制台中看到文件夹,但在 Amazon S3 中没有真正的 'folders'。它们只是基于包含文件夹前缀后跟正斜杠的对象键进行模拟。例如,前缀为 A/
的对象的存在表示名为 A
.
的逻辑文件夹
在删除唯一一个在其对象键中带有 'folder' 的对象后,不再有在其键中带有“文件夹”的对象,因此“文件夹”也随对象一起消失。
您必须自己重新创建 'folder'。
请参阅 documentation 了解如何手动创建文件夹,即 AWS 控制台中“创建文件夹”选项的作用:
When you use the Amazon S3 console to create a folder, Amazon S3 creates a 0-byte object with a key that's set to the folder name that you provided. For example, if you create a folder named photos in your bucket, the Amazon S3 console creates a 0-byte object with the key photos/. The console creates this object to support the idea of folders.
The Amazon S3 console treats all objects that have a forward slash (/) character as the last (trailing) character in the key name as a folder (for example, examplekeyname/). You can't upload an object that has a key name with a trailing / character by using the Amazon S3 console. However, you can upload objects that are named with a trailing / with the Amazon S3 API by using the AWS CLI, AWS SDKs, or REST API.
在S3中,我有一个只有1个文件的文件夹A。
我想将该文件移动到文件夹 B,如将文件从 A 复制到 B,然后将其从 A 中删除。
但是CDK在删除文件的同时也删除了A文件夹。我想保留这两个文件夹。
为什么要删除文件夹?如何告诉 CDK 不要删除?
虽然您在 AWS 控制台中看到文件夹,但在 Amazon S3 中没有真正的 'folders'。它们只是基于包含文件夹前缀后跟正斜杠的对象键进行模拟。例如,前缀为 A/
的对象的存在表示名为 A
.
在删除唯一一个在其对象键中带有 'folder' 的对象后,不再有在其键中带有“文件夹”的对象,因此“文件夹”也随对象一起消失。
您必须自己重新创建 'folder'。
请参阅 documentation 了解如何手动创建文件夹,即 AWS 控制台中“创建文件夹”选项的作用:
When you use the Amazon S3 console to create a folder, Amazon S3 creates a 0-byte object with a key that's set to the folder name that you provided. For example, if you create a folder named photos in your bucket, the Amazon S3 console creates a 0-byte object with the key photos/. The console creates this object to support the idea of folders.
The Amazon S3 console treats all objects that have a forward slash (/) character as the last (trailing) character in the key name as a folder (for example, examplekeyname/). You can't upload an object that has a key name with a trailing / character by using the Amazon S3 console. However, you can upload objects that are named with a trailing / with the Amazon S3 API by using the AWS CLI, AWS SDKs, or REST API.