How to compare local file with Amazon s3 file

。_饼干妹妹 提交于 2019-12-10 11:58:31

问题


I'm working on a desktop Java application. It needs to check for a specific file on my S3 server.

I don't want to download the entire file to compare, I need to find out if the one in the server is newer then the local one and then download and replace.

I'm not sure how to do the check if newer available part of this.

I've heard of hashing as a method but I have little experience with how to actually do that on both fronts (locally and via S3)


回答1:


To get the hash of the remote file: How to get the md5sum of a file on Amazon's S3

To get the hash of the local file: Getting a File's MD5 Checksum in Java




回答2:


Compare E-Tag programmatically for file with size < 5 GB.

Compute hash for local file:

String hash = DigestUtils.md5Hex(new FileInputStream(path));

Get Etag of S3 Object:Get Etag of S3 Object Already mentioned by @dnault

If you compute hash as explained above, then it should be same for all the cases when file size is less than 5 GB.

If file size is greater than 5 GB: Multi-part MD5




回答3:


If you are also the one originally creating the file on S3, you can store custom ObjectMetadata with an MD5 (e.g. meta.setUserMetadata(mymap)) when you first putObject(), and then look this up with s3.getObjectMetadata().



来源:https://stackoverflow.com/questions/14591926/how-to-compare-local-file-with-amazon-s3-file

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!