# How to download any file using send\_file() method

**URL:** <https://www.ruby-forum.com/t/how-to-download-any-file-using-send-file-method/112895>\
**Category:** Rails\
**Created:** [August 24, 2007, 7:22am UTC](https://www.ruby-forum.com/t/how-to-download-any-file-using-send-file-method/112895 "2007-08-24T07:22:23Z")\
**Posts on this page:** 1\
**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 24, 2007, 7:22am UTC](https://www.ruby-forum.com/t/how-to-download-any-file-using-send-file-method/112895/1 "2007-08-24T07:22:23Z")

</div>

HI,

I am directory listing and in that listing I have certain files and sub  
directories, now when I click on the files it should download that  
particular file but I am not able to accomplish it, and I have got to  
use send\_file() method.

In the send file Code shown below I have made use of the address of one  
of the files directly so when I click the link of any file it downloads  
it.

THE CODE  
…

def listing

```
          if (params[:dir] !=nil)
               @path = params[:path]+"/"+params[:dir]
          else
               @path ="D:/hr"
          end

               @f=File.ftype(@path)
                          if @f=="file"
                                redirect_to

```

:action=\>‘download\_files’  
else  
@dirEntries = Dir.entries(@path)  
@dirEntries.reject! { |filename|  
filename.starts\_with? ‘.’ }  
end  
end

```
      def download_files

                                send_file('D:/hr/xyz.doc',
                                             :filename =>

```

params[:filename] ,  
:type =\>  
‘application/octet-stream’,  
:disposition =\>  
‘attachment’,  
:streaming =\>  
‘true’,  
:buffer\_size =\>  
‘4096’)  
end
