# Send\_file() method for downloading any file

**URL:** <https://www.ruby-forum.com/t/send-file-method-for-downloading-any-file/113067>\
**Category:** Rails\
**Created:** [August 27, 2007, 6:29am UTC](https://www.ruby-forum.com/t/send-file-method-for-downloading-any-file/113067 "2007-08-27T06:29:44Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![advait](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/a/e19adc/32.png) [@advait](https://www.ruby-forum.com/u/advait)\
**Post date:** [August 27, 2007, 6:29am UTC](https://www.ruby-forum.com/t/send-file-method-for-downloading-any-file/113067/1 "2007-08-27T06:29:44Z")

</div>

HI,

I need to know how to download any file using send\_file() method.The  
code I have shown below is for a specific file…how ever I need it  
for any file.

THE CODE  
…

def download\_files

send\_file(‘D:/hr/Handbook.doc’,  
:filename =\> params[:filename] ,  
:type =\> ‘application/octet-stream’,  
:disposition =\> ‘attachment’,  
:stream =\> true,  
:buffer\_size =\> ‘4096’)

end

D:/hr/Handbook.doc is the particular file address, I need to specify an  
address that downloads any file when the respective link is clicked.

---

<div class="post-metadata">

**Author:** ![advait](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/a/e19adc/32.png) [@advait](https://www.ruby-forum.com/u/advait)\
**Post date:** [August 27, 2007, 2:22pm UTC](https://www.ruby-forum.com/t/send-file-method-for-downloading-any-file/113067/2 "2007-08-27T14:22:14Z")

</div>

Advait B. wrote:

> HI,
> 
> I need to know how to download any file using send\_file() method.The  
> code I have shown below is for a specific file…how ever I need it  
> for any file.
> 
> THE CODE  
> …
> 
> def download\_files
> 
> send\_file(‘D:/hr/Handbook.doc’,  
> :filename =\> params[:filename] ,  
> :type =\> ‘application/octet-stream’,  
> :disposition =\> ‘attachment’,  
> :stream =\> true,  
> :buffer\_size =\> ‘4096’)
> 
> end
> 
> D:/hr/Handbook.doc is the particular file address, I need to specify an  
> address that downloads any file when the respective link is clicked.

do something like this first u need to find the file

def download  
@document = Document.find(params[:id])  
send\_file(@document.full\_filename,  
:filename =\> @document.filename,  
:type =\> @document.content\_type,  
:disposition =\> ‘attachment’)  
end

hope this helps
