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 | = | "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["Content-Length"] ||= body.map(&:bytesize).inject(0, :+).to_s 95 96 [status, headers, body] 97 end
inspect()
[show source]
# File lib/shrine/plugins/upload_endpoint.rb 99 def inspect 100 "#<#{@shrine_class}::UploadEndpoint(:#{@storage_key})>" 101 end