Search code examples
amazon-web-servicesamazon-s3aws-sdk-js

How to check if file already uploaded to AWS S3?


In my application I want to prevent reuploading a file to AWS S3. I found the AWS JavaScript headObject useful

https://docs.aws.amazon.com/AWSJavaScriptSDK/latest/AWS/S3.html#headObject-property

But I not only want to compare the file name but also its content.

Thank you!


Solution

  • From Common Response Headers - Amazon Simple Storage Service:

    Objects encrypted by SSE-S3 or plaintext have ETags that are an MD5 digest of their data

    If your object meet this criteria, you can perform an MD5 on the local file and compare it with the ETag returned by headObject(). If they match, then the contents is the same.