Skip to content

Instantly share code, notes, and snippets.

@martinos
Created August 30, 2010 17:43
Show Gist options
  • Save martinos/557745 to your computer and use it in GitHub Desktop.
Save martinos/557745 to your computer and use it in GitHub Desktop.
AWS::S3::Base.establish_connection!(
:access_key_id => ENV['AMAZON_ACCESS_KEY_ID'],
:secret_access_key => ENV['AMAZON_SECRET_ACCESS_KEY']
)
def remote_serve(file_content, ext = "html", expires_in = 60 * 60 * 2 * 365)
# To generate a unique filename to avoid name colision
filename = Digest::SHA1.hexdigest(file_content + Time.now.to_s) + "." + ext.to_s
bucket_name = 'RemoteAccess'
obj = AWS::S3::S3Object.store(filename, file_content, bucket_name)
AWS::S3::S3Object.url_for(filename, bucket_name)
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment