module Shrine::Plugins::UploadEndpoint::ClassMethods
Public Instance Methods
# File lib/shrine/plugins/upload_endpoint.rb 29 def upload_endpoint(storage_key, **) 30 Shrine::UploadEndpoint.new( 31 shrine_class: self, 32 storage_key: storage_key, 33 **opts[:upload_endpoint], 34 **, 35 ) 36 end
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.
# File lib/shrine/plugins/upload_endpoint.rb 44 def upload_response(storage_key, env, **) 45 script_name = env["SCRIPT_NAME"] 46 path_info = env["PATH_INFO"] 47 48 begin 49 env["SCRIPT_NAME"] += path_info 50 env["PATH_INFO"] = "" 51 52 upload_endpoint(storage_key, **).call(env) 53 ensure 54 env["SCRIPT_NAME"] = script_name 55 env["PATH_INFO"] = path_info 56 end 57 end
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.