I’m a newbie having trouble using send_data to send a jpeg file to the
browser for display in an html img tag. This is the relevant code
from my controller (photos_controller.rb):
def retrieve
@photo = Photo.find(params[:id])
send_data File.read(@photo.abs_img_path), :type => “image/
jpeg”, :disposition => “inline”
end
def download
@photo = Photo.find(params[:id])
send_file @photo.abs_img_path, :type => “image/jpeg”, :filename =>
@photo.filename
end
In my html.erb file I have the following tags:
<%= image_tag retrieve_photo_path(@photo) %>
…
<%= link_to “Download photo”, download_photo_path(@photo) %>
I get a broken image in the browser. I see the html src correctly has
the image tag . If I browse directly to
“应用宝官网-全网最新最热手机应用游戏下载”, I just get the text “http://
应用宝官网-全网最新最热手机应用游戏下载” spit back to the browser (I’m using
Firefox). The download link works perfectly, so I know the routes
work, the file exists and isn’t corrupted, etc.
What am I missing with that send_data method? I’m using InstantRails
on Win XP, updated to Rails 2.3.4, Ruby 1.8.6. I’ve been banging my
head on this for a little while and I have a feeling I’m missing
something obvious…