Class: Shutterbug::Handlers::DirectUploadHandler

Inherits:
Object
  • Object
show all
Defined in:
lib/shutterbug/handlers/direct_upload_handler.rb

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.regexObject



9
10
11
# File 'lib/shutterbug/handlers/direct_upload_handler.rb', line 9

def self.regex
  /#{Configuration.instance.path_prefix}\/img_upload_url/
end

Instance Method Details

#handle(helper, req, env) ⇒ Object

Returns put_url and get_url for a new file that should be uploaded by the client. Of course get_url will work after file is uploaded.



15
16
17
18
19
20
21
22
23
24
25
26
27
# File 'lib/shutterbug/handlers/direct_upload_handler.rb', line 15

def handle(helper, req, env)
  format = req.GET()['format'] || 'png'

  object_name = "img-#{SecureRandom.uuid}.#{format}"
  storage = Configuration.instance.storage
  unless storage.respond_to? :put_url
    return helper.response('direct upload not available', 'text/plain', 400)
  end
  helper.response({
    put_url: storage.put_url(object_name),
    get_url: storage.get_url(object_name),
  }.to_json, 'application/json')
end