简体   繁体   中英

How can I display a BLOB stored image using Ruby and Sequel

I am not using Rails, so the send_data function will not work, unfortunately.

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

Check out the source of send_file method:

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

You can try doing the same, only set the body to image.image instead of reading it from a file.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM