简体   繁体   English

如何在 Java 中将我的文件夹同步到 Amazon S3

[英]How do I sync my folder to Amazon S3 in Java

I am building a java application as a learning exercise.我正在构建一个 java 应用程序作为学习练习。 For now, I want to make an app that will take the contents in a folder and replicate it to my Amazon S3 bucket.现在,我想制作一个应用程序,它将获取文件夹中的内容并将其复制到我的 Amazon S3 存储桶中。 By searching around, I found out that the best way to tell if 2 files are identical is to take the MD5 value.通过四处搜索,我发现判断 2 个文件是否相同的最佳方法是获取 MD5 值。

How do I iteratively take the MD5 of each file in my bucket?如何迭代地获取存储桶中每个文件的 MD5?

According to this link: http://docs.amazonwebservices.com/AmazonS3/latest/dev/index.html?ListingObjectKeysUsingJava.html根据此链接: http://docs.amazonwebservices.com/AmazonS3/latest/dev/index.html?ListingObjectKeysUsingJava.ZFC35FDC70D5FC69D269883A822CEZA7

The ObjectListing class can list the object keys and (metadata?) of your files in the bucket. ObjectListing class 可以列出存储桶中文件的 object 键和(元数据?)。 But, it doesn't really specify how I can interact with the files.但是,它并没有真正指定我如何与文件交互。 For example, for my local files, I use guava and does something like this:例如,对于我的本地文件,我使用 guava 并执行以下操作:

MessageDigest md = MessageDigest.getInstance("MD5");
byte[] md4 = Files.getDigest(localFile, md);

Looking at the AWS S3 API, you can use S3Object.getObjectContent() which will return an InputStream.查看 AWS S3 API,您可以使用将返回 InputStream 的 S3Object.getObjectContent()。 Is that the best way to work with the objects directly on S3?这是直接在 S3 上处理对象的最佳方式吗?

Finally, what is the best way to sync from my local folder to a bucket in S3?最后,从我的本地文件夹同步到 S3 中的存储桶的最佳方式是什么? Any tips is welcomed.欢迎任何提示。

Thanks!!!!谢谢!!!!

ObjectListing objectListing = s3.listObjects(
  new ListObjectsRequest().withBucketName(bucket));
List<S3ObjectSummary> l = objectListing.getObjectSummaries();

S3ObjectSummary has memeber called eTag which is md5 hash of the object S3ObjectSummary有一个名为eTag的成员,它是 md5 hash 的 object

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM