Created
June 20, 2015 15:45
-
-
Save miketheman/3e9c7338d00818a70e3f to your computer and use it in GitHub Desktop.
Use the AWS SDK Ruby gem to create new copies of objects without an invalid Content-Encoding metadata field
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env ruby | |
require 'aws-sdk' | |
INVALID_ENCODINGS = %w(ANSI_X3.4-1968 UTF-8) | |
bucket = Aws::S3::Bucket.new( | |
region: 'us-east-1', | |
name: 'www.mysite.com' | |
) | |
fail unless bucket.exists? | |
bucket.objects.each do |objectsummary| | |
obj = objectsummary.object | |
next unless INVALID_ENCODINGS.include?(obj.content_encoding) | |
obj_source = "#{obj.bucket_name}/#{obj.key}" | |
printf "%-60s %-8s %-24s %s\n", | |
obj.key, obj.content_encoding, obj.content_type, obj_source | |
objectsummary.copy_from( | |
copy_source: obj_source, | |
content_encoding: nil, | |
content_type: obj.content_type, | |
metadata: obj.metadata, | |
metadata_directive: 'REPLACE' | |
) | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment