class Shutterbug::Handlers::DirectUploadHandler

Public Class Methods

regex() click to toggle source
# File lib/shutterbug/handlers/direct_upload_handler.rb, line 15
def self.regex
  /#{Configuration.instance.path_prefix}\/img_upload_url/
end

Public Instance Methods

handle(helper, req, env) click to toggle source

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.

# 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) click to toggle source
# 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_upload() click to toggle source
# 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