class Shrine::UploadEndpoint
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.
Constants
- CONTENT_TYPE_JSON
- CONTENT_TYPE_TEXT
Public Class Methods
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
Writes given options to instance variables.
Public Instance Methods
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
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.
Source
# File lib/shrine/plugins/upload_endpoint.rb 101 def inspect 102 "#<#{@shrine_class}::UploadEndpoint(:#{@storage_key})>" 103 end
Also aliased as: to_s