class Shrine::UploadEndpoint

  1. lib/shrine/plugins/upload_endpoint.rb
Superclass: Object

Rack application that accepts multipart POST request to the root URL, calls upload with the uploaded file, and returns the uploaded file information in JSON format.

Methods

Public Class

  1. new

Public Instance

  1. call
  2. inspect

Constants

CONTENT_TYPE_JSON = "application/json; charset=utf-8"  
CONTENT_TYPE_TEXT = "text/plain"  

Public Instance Aliases

to_s -> inspect

Public Class methods

new(options)

Writes given options to instance variables.

[show source]
   # File lib/shrine/plugins/upload_endpoint.rb
72 def initialize(options)
73   options.each do |name, value|
74     instance_variable_set("@#{name}", value)
75   end
76 end

Public Instance methods

call(env)

Accepts a Rack env hash, routes POST requests to the root URL, and returns a Rack response triple.

If request isn’t to the root URL, a 404 Not Found response is returned. If request verb isn’t GET, a 405 Method Not Allowed response is returned.

[show source]
   # File lib/shrine/plugins/upload_endpoint.rb
84 def call(env)
85   request = Rack::Request.new(env)
86 
87   status, headers, body = catch(:halt) do
88     error!(404, "Not Found") unless ["", "/"].include?(request.path_info)
89     error!(405, "Method Not Allowed") unless request.post?
90 
91     handle_request(request)
92   end
93 
94   headers = Rack::Headers[headers] if Rack.release >= "3"
95   headers["Content-Length"] ||= body.respond_to?(:bytesize) ? body.bytesize.to_s :
96                                                               body.map(&:bytesize).inject(0, :+).to_s
97 
98   [status, headers, body]
99 end
inspect()
[show source]
    # File lib/shrine/plugins/upload_endpoint.rb
101 def inspect
102   "#<#{@shrine_class}::UploadEndpoint(:#{@storage_key})>"
103 end