Skip to content

Instantly share code, notes, and snippets.

@IndianGuru
Created September 5, 2011 10:07
Show Gist options
  • Save IndianGuru/1194616 to your computer and use it in GitHub Desktop.
Save IndianGuru/1194616 to your computer and use it in GitHub Desktop.
JRuby and Amazon S3
require "rubygems"
require "bundler/setup"
require 'yaml'
require 'aws-sdk'
#require 'jruby-openssl'
bucket_name = "talim"
file_name = "jrubyaws.txt"
# load_file(filepath)
# loads a document from the file located at filepath
config = YAML::load_file('config.yml')
AWS.config(config)
# get an instance of the S3 interface using the default configuration
s3 = AWS::S3.new
# create a bucket
b = s3.buckets.create(bucket_name)
# upload a file
basename = File.basename(file_name)
o = b.objects[basename]
o.write(:file => file_name)
puts "Uploaded #{file_name} to:"
puts o.public_url
# generate a presigned URL
puts "\nUse this URL to download the file:"
puts o.url_for(:read)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment