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



15
16
17
# File 'lib/shutterbug/handlers/direct_upload_handler.rb', line 15

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.



21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
# File 'lib/shutterbug/handlers/direct_upload_handler.rb', line 21

def handle(helper, req, env)
  if skip_direct_upload
    not_available_response(helper)
  else
    format = req.GET()['format'] || 'png'
    object_name = "img-#{SecureRandom.uuid}.#{format}"
    storage = Configuration.instance.storage
    unless storage.respond_to? :put_url
      not_available_response(helper)
    end
    helper.response({
      put_url: storage.put_url(object_name),
      get_url: storage.get_url(object_name),
    }.to_json, 'application/json')
  end
end

#not_available_response(helper) ⇒ Object



38
39
40
# File 'lib/shutterbug/handlers/direct_upload_handler.rb', line 38

def not_available_response(helper)
  return helper.response('direct upload not available', 'text/plain', 400)
end

#skip_direct_uploadObject



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

def skip_direct_upload
  return true if Configuration.instance.skip_direct_upload
  return true unless Configuration.instance.use_s3?
  return false
end