0

我有幾個文件上傳和文件分組在一個文件夾中。我有一個批量下載按鈕,將下載該文件夾中的所有文件。當他們點擊按鈕下載時,它將運行此方法。Rails Combine載波上傳到可下載的Zip文件

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內部拉鍊提取器時,它將生成一個未指定的錯誤0x80004005

儘管能夠使用WinRAR或7Zip下載和打開文件,但我並不認爲這是一個有效的解決方案。任何想法如何我可以改變download_multiple方法,以便它可以讓Windows打開ZIP文件,而不需要Windows附帶的任何壓縮軟件?

回答

0

最近的gem更新已經解決了這個問題。