Rails を使っていないのでsend_data
、残念ながら機能しません。
image = User.select("image, image_mime").where("username = '#{params[:name]}'").first
send_data( image.image,
:type => image.image_mime,
:disposition => 'inline')
send_file
メソッドのソースを確認してください。
def send_file(filename, content_type = nil, content_disposition = nil)
content_type ||= Rack::Mime.mime_type(::File.extname(filename))
content_disposition ||= File.basename(filename)
response.body = ::File.open(filename, 'rb')
response['Content-Length'] = ::File.size(filename).to_s
response['Content-Type'] = content_type
response['Content-Disposition'] = content_disposition
response.status = 200
throw(:respond, response)
end
image.image
ファイルから読み取るのではなく、本文をに設定するだけで、同じことを試すことができます。