Module: Shrine::Plugins::UploadEndpoint::ClassMethods
- Defined in:
- lib/shrine/plugins/upload_endpoint.rb
Instance Method Summary collapse
-
#upload_endpoint(storage_key) ⇒ Object
Returns a Rack application (object that responds to
#call) which accepts multipart POST requests to the root URL, uploads given file to the specified storage, and returns that information in JSON format. -
#upload_response(storage_key, env) ⇒ Object
Calls the upload endpoint passing the request information, and returns the Rack response triple.
Instance Method Details
#upload_endpoint(storage_key) ⇒ Object
Returns a Rack application (object that responds to #call) which
accepts multipart POST requests to the root URL, uploads given file
to the specified storage, and returns that information in JSON format.
The storage_key needs to be one of the registered Shrine storages.
Additional options can be given to override the options given on
plugin initialization.
29 30 31 32 33 34 35 36 |
# File 'lib/shrine/plugins/upload_endpoint.rb', line 29 def upload_endpoint(storage_key, **) Shrine::UploadEndpoint.new( shrine_class: self, storage_key: storage_key, **opts[:upload_endpoint], **, ) end |
#upload_response(storage_key, env) ⇒ Object
Calls the upload endpoint passing the request information, and returns the Rack response triple.
It performs the same mounting logic that Rack and other web frameworks use, and is meant for cases where statically mounting the endpoint in the router isn't enough.
44 45 46 47 48 49 50 51 52 53 54 55 56 57 |
# File 'lib/shrine/plugins/upload_endpoint.rb', line 44 def upload_response(storage_key, env, **) script_name = env["SCRIPT_NAME"] path_info = env["PATH_INFO"] begin env["SCRIPT_NAME"] += path_info env["PATH_INFO"] = "" upload_endpoint(storage_key, **).call(env) ensure env["SCRIPT_NAME"] = script_name env["PATH_INFO"] = path_info end end |