How downloading image in rails


#1

Hi everybody,

I want to display a link for downloading image from database.

def image
@image = Classified.find(params[:id])
send_data @image.picture, :filename => “photo.jpg”,
:type => @image.content_type, :disposition => “attachment”

end

<%= image_tag (url_for({:action => ‘image’,
:id => @classified.id})) -%>

But its still display the image only not displaying the link to
download.

I use both :disposition as “inline” and “attachment”. But I cant get the
link to download the image file. How is it possible. Please advice me.

Regards,
Veeraa


#2

Take a look at send_data method. Use this method within a controller
action to send the data for your image to the client browser. You
will then connect your action to a regular hyperlink within your view
in the normal way.

On May 7, 10:20 am, Veera S. <rails-mailing-l…@andreas-


#3

Robert W. wrote:

Take a look at send_data method. Use this method within a controller
action to send the data for your image to the client browser. You
will then connect your action to a regular hyperlink within your view
in the normal way.

On May 7, 10:20 am, Veera S. <rails-mailing-l…@andreas-

HI Robert,

Thanks for your kind reply. Thanks a lot.

By veeraa…