module Shrine::Plugins::PresignEndpoint::ClassMethods

  1. lib/shrine/plugins/presign_endpoint.rb


Public Instance

  1. presign_endpoint
  2. presign_response

Public Instance methods

presign_endpoint(storage_key, **options)

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.

[show source]
   # File lib/shrine/plugins/presign_endpoint.rb
24 def presign_endpoint(storage_key, **options)
26     shrine_class: self,
27     storage_key:  storage_key,
28     **opts[:presign_endpoint],
29     **options,
30   )
31 end
presign_response(storage_key, env, **options)

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.

[show source]
   # File lib/shrine/plugins/presign_endpoint.rb
39 def presign_response(storage_key, env, **options)
40   script_name = env["SCRIPT_NAME"]
41   path_info   = env["PATH_INFO"]
43   begin
44     env["SCRIPT_NAME"] += path_info
45     env["PATH_INFO"]    = ""
47     presign_endpoint(storage_key, **options).call(env)
48   ensure
49     env["SCRIPT_NAME"] = script_name
50     env["PATH_INFO"]   = path_info
51   end
52 end