# Download a file

**URL:** <https://www.ruby-forum.com/t/download-a-file/125874>\
**Category:** Rails\
**Created:** [January 13, 2008, 7:00am UTC](https://www.ruby-forum.com/t/download-a-file/125874 "2008-01-13T07:00:42Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![nettome](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/n/f04885/32.png) [@nettome](https://www.ruby-forum.com/u/nettome)\
**Post date:** [January 13, 2008, 7:00am UTC](https://www.ruby-forum.com/t/download-a-file/125874/1 "2008-01-13T07:00:42Z")

</div>

I want to download a file previously uploaded in the database  
Its like providing a link and when clicked the file is downloaded to  
your file system  
How?? can i do that, I have no idea about it  
Please can anyone help me

Online

---

<div class="post-metadata">

**Author:** ![nettome](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/n/f04885/32.png) [@nettome](https://www.ruby-forum.com/u/nettome)\
**Post date:** [January 13, 2008, 5:59pm UTC](https://www.ruby-forum.com/t/download-a-file/125874/2 "2008-01-13T17:59:16Z")

</div>

also check out attachment\_fu plugin for all round file upload/download  
handling.

---

<div class="post-metadata">

**Author:** ![nettome](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/n/f04885/32.png) [@nettome](https://www.ruby-forum.com/u/nettome)\
**Post date:** [January 13, 2008, 6:09pm UTC](https://www.ruby-forum.com/t/download-a-file/125874/3 "2008-01-13T18:09:49Z")

</div>

You should use the send\_file or send\_data methods available from the  
controller

send\_data method(if the file is stored as a BLOB in the db)  
send\_data image.data, :type =\> image.content\_type, :disposition =\>  
‘attachment’

in this example (from the api docs) this implies you have an  
activerecord model called Image, with the fields ‘data’ and  
‘content\_type’

send\_file method (if the file is in the file system (can be outside  
rails/public root)  
send\_file ‘/path/to.jpeg’, :type =\> ‘image/jpeg’, :disposition =\>  
‘attachment’

Look them up here: [www.gotapi.com/rubyrails](http://www.gotapi.com/rubyrails)

Joe

---

<div class="post-metadata">

**Author:** ![nettome](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/n/f04885/32.png) [@nettome](https://www.ruby-forum.com/u/nettome)\
**Post date:** [January 14, 2008, 5:25am UTC](https://www.ruby-forum.com/t/download-a-file/125874/4 "2008-01-14T05:25:52Z")

</div>

thanks man i would look into it

---

<div class="post-metadata">

**Author:** ![nettome](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/n/f04885/32.png) [@nettome](https://www.ruby-forum.com/u/nettome)\
**Post date:** [January 14, 2008, 7:06am UTC](https://www.ruby-forum.com/t/download-a-file/125874/5 "2008-01-14T07:06:55Z")

</div>

hi,  
I want to provide a link “Download Image” which when clicked the image  
is downloaded to the desired file system  
Please can u help ,  
I used the send\_data function in my program for displaying the image.
