0

Rails を使っていないのでsend_data、残念ながら機能しません。

image = User.select("image, image_mime").where("username = '#{params[:name]}'").first
  send_data( image.image,
             :type => image.image_mime,
             :disposition => 'inline')
4

1 に答える 1

2

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ファイルから読み取るのではなく、本文をに設定するだけで、同じことを試すことができます。

于 2012-09-30T18:33:30.050 に答える