Sinatra: how to respond with an image with the headings "content-type" => "image / jpeg"
Example:
require 'sinatra'
get '/somekey' do
headers('Content-Type' => "image/jpeg")
["http://upload.wikimedia.org/wikipedia/commons/2/23/Lake_mapourika_NZ.jpeg", "http://img.brothersoft.com/screenshots/softimage/j/jpeg_converter-4567-1.jpeg"].sample
end
I want to respond with an image that is not hosted on my server.
How do I know this?
Note: The link to the image is not secret (since it is posted on S3). It is for the site that identifiers are generated.
Checkout http://identico.in/[insert_any_key_here] . The reason is because I wanted the server to view if the image already exists on S3, use it, if not, generate it and then upload it to s3.
Note: If I did:
require "open-uri"
open ["http://upload.wikimedia.org/wikipedia/commons/2/23/Lake_mapourika_NZ.jpeg", "http://img.brothersoft.com/screenshots/softimage/j/jpeg_converter-4567-1.jpeg"].sample
, , , , , .
, , . send_file open('link')
- .
require 'sinatra'
require 'open-uri'
get '/' do
send_file open('http://upload.wikimedia.org/wikipedia/commons/2/23/Lake_mapourika_NZ.jpeg'),
type: 'image/jpeg',
disposition: 'inline'
end
, javascript, .
require 'sinatra'
get '/' do
"<script>document.location = 'http://upload.wikimedia.org/wikipedia/commons/2/23/Lake_mapourika_NZ.jpeg'</script>
end