Ruby(非 Rails)CGI 脚本输出文件可供下载
我正在尝试获取一个脚本来输出 zip 文件以供下载。
该脚本基本上是:
#!/usr/bin/env ruby
require 'rubygems'
require 'active_support'
require 'zip/zip'
require 'cgi'
temp_zip_filename = '/some/path/tmp/' + Time.new.usec.to_s
new_zip = File.open(temp_zip_filename, 'rb'){|f| f.read}
#header = "Content-Type: application/octet-stream"
#header << ' Content-Disposition: attachement; filename="AZipFile.zip"'
CGI.new.out 'application/zip' do
new_zip
end
我看不到任何可以在请求计算机上设置下载文件名称的地方。它似乎总是保存为“scriptname.cgi”。在哪里可以设置 CGI 的内容配置?
I'm trying to get a script to output a zip file for download.
The script is basically:
#!/usr/bin/env ruby
require 'rubygems'
require 'active_support'
require 'zip/zip'
require 'cgi'
temp_zip_filename = '/some/path/tmp/' + Time.new.usec.to_s
new_zip = File.open(temp_zip_filename, 'rb'){|f| f.read}
#header = "Content-Type: application/octet-stream"
#header << ' Content-Disposition: attachement; filename="AZipFile.zip"'
CGI.new.out 'application/zip' do
new_zip
end
I can't see anywhere I can set the downloaded file's name on the requesting computer. It always seems to get saved as "scriptname.cgi". Where can I set the content disposition with CGI?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
听起来您想要
标头
方法:
Sounds like you want the
header
method on CGI:我相信您想要:
请参阅
CGI 的文档#out
。I believe you want:
See the documentation for
CGI#out
.