Rails如何通过控制器提供文件下载?

时间:2022-12-19 20:39:12

I want to make a list of file download links to files in my local folder
when I use this
<a href="/home/tmpfile.txt">download_link</a>
It complains
No route matches [GET] "/home/tmpfile.txt"
and
<%=link_to "download_link","/home/tmpfile.txt"%>
also get
No route matches [GET] "/home/tmpfile.txt"
add get "/home/tmpfile.txt" to config/route.rb does not solve the problem

当我使用此 download_link 时,我想列出文件下载链接到本地​​文件夹中的文件。它抱怨没有路由匹配[GET]“/ home / tmpfile.txt“和<%= link_to”download_link“,”/ home / tmpfile.txt“%>也得到无路由匹配[GET]”/ home / tmpfile.txt“add get”/home/tmpfile.txt“to config / route.rb无法解决问题

I dont want to use the send_file function in controller because I have a lot of files
I am looking for something like this
ftp://ftp.ncbi.nih.gov/pub/mmdb/cdd/

我不想在控制器中使用send_file函数,因为我有很多文件,我正在寻找像这样的东西ftp://ftp.ncbi.nih.gov/pub/mmdb/cdd/

Does anyone have a simple solution?

有人有一个简单的解决方案吗?

1 个解决方案

#1


1  

Is /home/tmpfile.txt the path in your filesystem or the path in the servers virtual filesystem? If its the path in the filesystem you need to move it to the public folder though its available in the webservers root directory!

/home/tmpfile.txt是文件系统中的路径还是服务器虚拟文件系统中的路径?如果它是文件系统中的路径,您需要将其移动到公共文件夹,尽管它在webservers根目录中可用!

#1


1  

Is /home/tmpfile.txt the path in your filesystem or the path in the servers virtual filesystem? If its the path in the filesystem you need to move it to the public folder though its available in the webservers root directory!

/home/tmpfile.txt是文件系统中的路径还是服务器虚拟文件系统中的路径?如果它是文件系统中的路径,您需要将其移动到公共文件夹,尽管它在webservers根目录中可用!