Send_file() method for downloading any file

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.

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

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