I have a controller that serves up images uploaded from a website. It does this via #send_data. In 4.1 and earlier, it sent the binary data. Starting with 4.2 the image starting going out escaped and no browser will render the image. Here is the code:
class BookCoversController < ApplicationController
def show
puts "request headers = #{request.headers}"
@image = BookCover.for_book_id(params[:book_id])
# We use only an ETag here so that clients will have to check that the image is still valid.
if stale?(:etag => @image.cache_key, template: false)
send_data(@image.image, :type => @image.content_type, :filename => "book_cover_#{@image.book_id}", :disposition => 'inline')
end
end
end
Here is what the response body looks like prior to Rails 4.2:
and here is what the data look like in Rails 4.2: