Skip to content

Instantly share code, notes, and snippets.

@bhenry
Forked from IndianGuru/jruby10.rb
Created July 29, 2016 15:20
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save bhenry/969f818f1ed5364b9acb3d8fa01e8ecb to your computer and use it in GitHub Desktop.
Save bhenry/969f818f1ed5364b9acb3d8fa01e8ecb 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