5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
|
# File 'lib/decode_base64_image.rb', line 5
def call(env)
request = Rack::Request.new(env)
content_type = request['content_type'] || 'image/png'
image_data = request['image_data']
begin
raise "Missing required parameter 'image_data'" if image_data.to_s.empty?
response = Rack::Response.new(Base64.decode64(image_data), 200, { 'Content-Type' => content_type })
response.['Cache-Control'] = "public, max-age=#{1.month}"
rescue Exception => e
response = Rack::Response.new(e.message, 500, { 'Content-Type' => 'text/plain' })
end
response.to_a
end
|