Windows 7 Rails将Carrierwave上载合并到可下载的Zip文件中
我有几个上传的文件,文件被分组在一个文件夹中。我有一个批量下载按钮,可以下载文件夹中的所有文件。当他们单击按钮下载时,它将运行此方法Windows 7 Rails将Carrierwave上载合并到可下载的Zip文件中,windows-7,ruby-on-rails-3.1,compression,download,carrierwave,Windows 7,Ruby On Rails 3.1,Compression,Download,Carrierwave,我有几个上传的文件,文件被分组在一个文件夹中。我有一个批量下载按钮,可以下载文件夹中的所有文件。当他们单击按钮下载时,它将运行此方法 def download_multiple @odocument = Odocument.find(params[:id]) @files = Redocument.find(:all, :conditions => {:odocument_id => @odocument.id}) t = Tempfile.new('tm
def download_multiple
@odocument = Odocument.find(params[:id])
@files = Redocument.find(:all, :conditions => {:odocument_id => @odocument.id})
t = Tempfile.new('tmp-zip-' + request.remote_ip)
Zip::ZipOutputStream.open(t.path) do |zos|
@files.each do |file|
zos.put_next_entry(File.basename(file.redocument.url))
zos.print IO.read(file.redocument.url)
end
end
filename = @odocument.document_name + ".zip"
t.close
send_file t.path, :type => "application/zip", :filename => filename
end
这将下载并创建ZIP文件,当使用WinRAR或7Zip时,它将提取文件,我可以成功地打开/编辑它们。但是,当使用Windows XP/Vista/7内部zip提取器时,它将生成一个未指定的错误0x80004005
尽管能够使用WinRAR或7Zip下载和打开文件,但我并不认为这是一个有效的解决方案。你知道我如何更改“下载多个”方法,使Windows能够在不使用Windows附带的任何压缩软件的情况下打开ZIP文件吗?最近的gem更新修复了这个问题