-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathserver.rb
More file actions
40 lines (32 loc) · 715 Bytes
/
server.rb
File metadata and controls
40 lines (32 loc) · 715 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
require 'rubygems'
require 'sinatra'
require 'haml'
require 'aws/s3'
get '/' do
haml :index
end
get '/images' do
AWS::S3::Base.establish_connection!(
:access_key_id => ENV['S3_KEY'],
:secret_access_key => ENV['S3_SECRET']
)
@images = AWS::S3::Bucket.objects('photobooth.heroku.com')
haml :images
end
post '/save' do
result = "success"
begin
AWS::S3::Base.establish_connection!(
:access_key_id => ENV['S3_KEY'],
:secret_access_key => ENV['S3_SECRET']
)
AWS::S3::S3Object.store(
"#{Time.now.to_i}.png",
File.open(request.body.path),
"photobooth.heroku.com"
)
rescue => e
result = "failure (#{e})"
end
result
end