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
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 <img src="photos/5/retrieve"/>. If I browse directly to "http://www.myapp.com/photos/5/retrieve", I just get the text "http:// www.myapp.com/photos/5/retrieve" 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...