Module: Shrine::Plugins::PresignEndpoint::ClassMethods

Defined in:
lib/shrine/plugins/presign_endpoint.rb

Instance Method Summary collapse

Instance Method Details

#presign_endpoint(storage_key, **options) ⇒ Object

Returns a Rack application (object that responds to ‘#call`) which accepts GET requests to the root URL, calls the specified storage to generate the presign, 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.



24
25
26
27
28
29
30
31
# File 'lib/shrine/plugins/presign_endpoint.rb', line 24

def presign_endpoint(storage_key, **options)
  Shrine::PresignEndpoint.new(
    shrine_class: self,
    storage_key:  storage_key,
    **opts[:presign_endpoint],
    **options,
  )
end

#presign_response(storage_key, env, **options) ⇒ Object

Calls the presign 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.



39
40
41
42
43
44
45
46
47
48
49
50
51
52
# File 'lib/shrine/plugins/presign_endpoint.rb', line 39

def presign_response(storage_key, env, **options)
  script_name = env["SCRIPT_NAME"]
  path_info   = env["PATH_INFO"]

  begin
    env["SCRIPT_NAME"] += path_info
    env["PATH_INFO"]    = ""

    presign_endpoint(storage_key, **options).call(env)
  ensure
    env["SCRIPT_NAME"] = script_name
    env["PATH_INFO"]   = path_info
  end
end