-
-
Save bhenry/969f818f1ed5364b9acb3d8fa01e8ecb to your computer and use it in GitHub Desktop.
JRuby and Amazon S3
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
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