在Ruby代码中下载文件(Download file in Ruby code)

编程入门 行业动态 更新时间:2024-10-17 23:29:11
在Ruby代码中下载文件(Download file in Ruby code)

欣任何想法如何在Ruby中下载文件我试试这个但它不起作用

在我的index.html.erb中,我这样做

require 'open-uri' def index File.open('/target/path/to/downloaded.file', "wb") do |file| file.write open('http://example.com/your.file').read end end

但它仍然无法正常工作

Hin Any ideas how to download File in Ruby i try this but it's not working

in my index.html.erb i do this

require 'open-uri' def index File.open('/target/path/to/downloaded.file', "wb") do |file| file.write open('http://example.com/your.file').read end end

but it's still not working

最满意答案

send_file应该像这样工作:

send_file "/target/path/to/downloaded.file", :filename => "your.file",

还有一些可用的参数:

:type => :x_sendfile => true

send_file should work like this:

send_file "/target/path/to/downloaded.file", :filename => "your.file",

also there are a few more params available:

:type => :x_sendfile => true

更多推荐

本文发布于:2023-07-25 05:45:00,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1256814.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:代码   文件   Ruby   code   file

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!