Created
March 30, 2011 14:08
-
-
Save jfairbairn/894452 to your computer and use it in GitHub Desktop.
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 ruby1.9.1 | |
# | |
# | |
# Testing streaming a single object into s3 | |
# In this case the kernel sources as they are a decent size for sending up | |
require 'fog' | |
key = 'AAAAA' | |
secret = 'BBBB' | |
region = 'eu-west-1' | |
bucket = 'some-random-bucket' | |
@stor = Fog::Storage.new(:provider => 'AWS', :aws_access_key_id => key, :aws_secret_access_key => secret, :region => region) | |
File.open('/tmp/linux-2.6.38.tar.bz2') do |file| | |
response = @stor.put_object(bucket, 'tmp/linux-2.6.38.tar.bz2', file) | |
end | |
# Or you can roll the following which would work with multiple providers: | |
dir = @stor.directories.new(:key => bucket) | |
dir.files.create(:key => 'tmp/linux-2.6.38.tar.bz2', :body => File.open('/tmp/linux-2.6.38.tar.bz2') ) | |
# For deletion: | |
file_to_delete = 'tmp/linux-2.6.38.tar.bz2' | |
dir = @stor.directories.new(:key => bucket) | |
file = dir.files.new(:key => file_to_delete) | |
file.destroy | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment