Skip to content

Instantly share code, notes, and snippets.

@jfairbairn
Created March 30, 2011 14:08
Show Gist options
  • Save jfairbairn/894452 to your computer and use it in GitHub Desktop.
Save jfairbairn/894452 to your computer and use it in GitHub Desktop.
#!/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