[英]download all files from S3 and upload them in same folder
I have enabled versioning on the bucket whenever a new bucket is created. 每当创建新存储桶时,我都会在存储桶上启用版本控制。 But for backward compatibility (buckets which are already created), i'm downloading all files/keys and uploading again.
但是为了向后兼容(已创建的存储桶),我正在下载所有文件/密钥并再次上传。 I'm doing this:
我正在这样做:
fullObject = s3Client.getObject(new GetObjectRequest(bucketName, key));
But i am not able to figure out while uploading how to upload file in their specific folder. 但是我无法在上传时弄清楚如何在其特定文件夹中上传文件。 Or is there another solution to fix backward compatibility.
还是有另一种解决向后兼容性的解决方案。
S3 doesn't really have folders, it "fakes" it with logic that looks for common prefixes separated by "/". S3确实没有文件夹,它使用逻辑来“伪造”它,以寻找以“ /”分隔的通用前缀。 The "key" is the full path name of the file within the bucket.
“密钥”是存储桶中文件的完整路径名。
It sounds like you are doing a get and then want to do a put of the same bytes to the same key in the bucket. 听起来您正在执行获取操作,然后想要将相同的字节放入存储桶中的相同密钥。 If that is what you want to do, then just use the same key that you used for getting the object.
如果这是您要执行的操作,则只需使用与获取对象相同的键即可。
In a bucket that has versioning turned on, this will result in two copies of the file. 在启用了版本控制的存储桶中,这将导致文件的两个副本。 It is not clear why you would want to do that (assuming that you are writing back exactly what you are reading).
目前尚不清楚您为什么要这么做(假设您正写回所读内容)。 Wouldn't you just end up paying for two copies of the same file?
您会不会最终要为同一文件的两个副本付费?
My understanding is that if you turn on versioning for a bucket that already has files in it, that everything works the way you would expect. 我的理解是,如果您为其中已经有文件的存储桶打开版本控制,那么一切都会以您期望的方式运行。 If a pre-existing file gets deleted, it just adds a delete marker.
如果先前存在的文件被删除,它只会添加一个删除标记。 If a pre-existing file gets overwritten, it keeps the prior version (as a prior version of the new file).
如果先前存在的文件被覆盖,它将保留先前版本(作为新文件的先前版本)。 There is no need to pro-actively rewrite existing files when you turn on versioning.
启用版本控制时,无需主动重写现有文件。 If you are concerned, you can easily test this through either the S3 Console, the command line interface, or through one of the language-specific APIs.
如果您有兴趣,可以通过S3控制台,命令行界面或特定于语言的API之一轻松进行测试。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.