Last active
August 29, 2015 14:22
-
-
Save frankpinto/4c5cc7d8272f994ea509 to your computer and use it in GitHub Desktop.
Ruby s3 SDK example
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
task :fix_image_headers => :environment do | |
puts "---------------------------------------------" | |
puts "Uploading ad images to tools.ayalo.co" | |
puts "---------------------------------------------" | |
# Set s3 credentials | |
Dotenv.load | |
# Example of Client interface | |
s3 = Aws::S3::Client.new | |
s3.list_objects(bucket: 'tools.ayalo.co').contents.each do |obj| | |
o = s3.get_object( | |
bucket: 'tools.ayalo.co', | |
key: obj.key | |
) | |
if !o.metadata.empty? | |
puts o.metadata | |
end | |
end | |
puts | |
object = s3.get_object( | |
bucket: 'tools.ayalo.co', | |
key: '1417201294_701da4733219c051b9d6f95adbcd5c93.jpg' | |
) | |
print 'Content-type: ', object.content_type, "\n" | |
print 'Content-length: ', object.content_length, "\n" | |
print 'Last-modified: ', object.last_modified, "\n" | |
print 'Cache-control: ', object.cache_control, "\n" | |
print 'Metadata: ', object.metadata, "\n" | |
print 'Metadata empty? ', object.metadata.empty?, "\n" | |
# Example of Resource interface | |
s3 = Aws::S3::Resource.new | |
bucket = s3.bucket('tools.ayalo.co') | |
bucket.objects.each do |o| | |
puts o.key | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment