I have several files that were uploaded and files are grouped in a folder. I have a mass download button that will download all of the files in the folder. When they click the button to download, it will run this method.
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
This will download and create the ZIP file and when using WinRAR or 7Zip it will extract the files and I can successfully open/edit them. However, when using Windows XP/Vista/7 internal zip extractor, it will generate an unspecified error 0x80004005.
Despite being able to download and open the files using WinRAR or 7Zip, I don’t really see this as an effective solution. Any idea how I can change the download_multiple method so that it will allow Windows to open the ZIP file without any compression software outside of what comes with Windows?
A recent gem update has fixed this issue.