简体   繁体   English

从S3下载所有文件并将它们上传到同一文件夹中

[英]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.

相关问题 spring boot 如何将s3文件夹中的所有文件下载到本地目录? - spring boot how to download all files in a folder of s3 to a local directory? 如何从Amazon S3下载文件? - How to download files from Amazon S3? 我们如何使用 Java SDK 从 S3 存储桶下载没有文件夹的多个文件 - How can we download multiple files without folder from S3 bucket using Java SDK AWS lambda函数可从s3检索所有上传的文件,然后将解压缩的文件夹再次上传回s3 - AWS lambda function to retrieve any uploaded files from s3 and upload the unzipped folder back to s3 again 将文件从GAE直接上传到S3 - Upload files from GAE to S3 directly ResourcePatternResolver 未列出 s3 中文件夹中的文件 - ResourcePatternResolver Not listing files from a folder in s3 如何从S3存储桶的各个文件夹中下载多个与文件名具有相同前缀的文件? - How to download multiple files having same prefix as filename from various folders of S3 bucket? 从S3存储桶下载压缩的.gz文件中的文件 - Download the files inside compressed .gz files from S3 Bucket Java解压缩所有文件,忽略目录并上传到S3 - Java Unzip all files, ignoring directories and upload to S3 如何在S3中设置文件夹中所有文件的ACL - How to set ACL of all files in a folder in S3
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM