Class: Shutterbug::Handlers::DirectUploadHandler
- Inherits:
-
Object
- Object
- Shutterbug::Handlers::DirectUploadHandler
- Defined in:
- lib/shutterbug/handlers/direct_upload_handler.rb
Class Method Summary collapse
Instance Method Summary collapse
-
#handle(helper, req, env) ⇒ Object
Returns put_url and get_url for a new file that should be uploaded by the client.
- #not_available_response(helper) ⇒ Object
- #skip_direct_upload ⇒ Object
Class Method Details
.regex ⇒ Object
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_upload ⇒ Object
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 |