Skip to content

Commit

Permalink
just supply zipname and have rails format it (#3694)
Browse files Browse the repository at this point in the history
Let Rails set content-type and content-disposition headers.
  • Loading branch information
johrstrom authored Aug 8, 2024
1 parent e21eb11 commit 2110bdb
Showing 1 changed file with 2 additions and 4 deletions.
6 changes: 2 additions & 4 deletions apps/dashboard/app/controllers/files_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -52,17 +52,15 @@ def fs
end

if can_download
zipname = "#{@path.basename.to_s.gsub('"', '\"')}.zip"
response.set_header 'Content-Disposition', "attachment; filename=\"#{zipname}\""
response.set_header 'Content-Type', 'application/zip'
zipname = "#{@path.basename}.zip"
response.set_header 'Last-Modified', Time.now.httpdate
response.sending_file = true
response.cache_control[:public] ||= false

zip_headers = ZipKit::OutputEnumerator.new.streaming_http_headers
response.headers.merge!(zip_headers)

send_stream(filename: zipname) do |stream|
send_stream(filename: zipname, disposition: 'attachment', type: :zip) do |stream|
ZipKit::Streamer.open(stream) do |zip|
@path.files_to_zip.each do |file|
next unless File.readable?(file.realpath)
Expand Down

0 comments on commit 2110bdb

Please sign in to comment.