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
--
Posted via http://www.ruby-forum.com/.
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups
"Ruby on Rails: Talk" group.
To post to this group, send email to
rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org
To unsubscribe from this group, send email to
rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org
For more options, visit this group at
http://groups.google.com/group/rubyonrails-talk?hl=en
-~----------~----~----~----~------~----~------~--~---
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
--
Posted via http://www.ruby-forum.com/.
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups
"Ruby on Rails: Talk" group.
To post to this group, send email to
rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org
To unsubscribe from this group, send email to
rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org
For more options, visit this group at
http://groups.google.com/group/rubyonrails-talk?hl=en
-~----------~----~----~----~------~----~------~--~---