Created
February 18, 2014 15:41
-
-
Save szabcsee/9073380 to your computer and use it in GitHub Desktop.
File upload to AWS S3 with ruby and sinatra
This file contains hidden or 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 'sinatra' | |
require 'aws/s3' | |
AWS::S3::Base.establish_connection!( | |
:access_key_id => 'key_id', | |
:secret_access_key => 'secret_access_key' | |
) | |
get '/upload' do | |
print 'Ez van a bucketekben:' | |
print AWS::S3::Service.buckets | |
erb :upload | |
end | |
# Handle POST-request (Receive and save the uploaded file) | |
post '/upload' do | |
bucket = AWS::S3::Bucket.find('mybucket') | |
file = params['myfile'][:tempfile] | |
AWS::S3::S3Object.store(file, open(file), bucket) | |
puts AWS::S3::Bucket.objects('mybucket').size | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment