How to download any file using send_file() method

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

This forum is not affiliated to the Ruby language, Ruby on Rails framework, nor any Ruby applications discussed here.

| Privacy Policy | Terms of Service | Remote Ruby Jobs