Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

File download using Paperclip

I am using Rails to make a small file upload app. For file attachment I am using the wonderful Paperclip but I can't work out how to do downloads.

How would I create a link in my show view, that is passed the file id, for instance that would allow the user to download a file on my server?

like image 476
seadowg Avatar asked Feb 16 '11 12:02

seadowg


2 Answers

If the file uploaded is attached to a model, e.g. as an attribute called avatar, then you can create a link like:

<%= link_to "Download", model.avatar.url(:original, false) %>

Replace avatar with the name of your attribute.

like image 157
Syed Aslam Avatar answered Nov 19 '22 23:11

Syed Aslam


Replace whatever by name that are user in your model for paper clip if you have

resource_file_name, resource_file_name, resource_file_name,

then replace whatever by resource

like image 21
Thorin Avatar answered Nov 20 '22 00:11

Thorin