module Shrine::Plugins::UploadEndpoint::ClassMethods

  1. lib/shrine/plugins/upload_endpoint.rb


Public Instance

  1. upload_endpoint
  2. upload_response

Public Instance methods

upload_endpoint(storage_key, **options)

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.

[show source]
   # File lib/shrine/plugins/upload_endpoint.rb
29 def upload_endpoint(storage_key, **options)
31     shrine_class: self,
32     storage_key:  storage_key,
33     **opts[:upload_endpoint],
34     **options,
35   )
36 end
upload_response(storage_key, env, **options)

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.

[show source]
   # File lib/shrine/plugins/upload_endpoint.rb
44 def upload_response(storage_key, env, **options)
45   script_name = env["SCRIPT_NAME"]
46   path_info   = env["PATH_INFO"]
48   begin
49     env["SCRIPT_NAME"] += path_info
50     env["PATH_INFO"]    = ""
52     upload_endpoint(storage_key, **options).call(env)
53   ensure
54     env["SCRIPT_NAME"] = script_name
55     env["PATH_INFO"]   = path_info
56   end
57 end