Skip to content

Instantly share code, notes, and snippets.

@szabcsee
Created February 18, 2014 15:41
Show Gist options
  • Save szabcsee/9073380 to your computer and use it in GitHub Desktop.
Save szabcsee/9073380 to your computer and use it in GitHub Desktop.
File upload to AWS S3 with ruby and sinatra
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