Skip to content

Commit

Permalink
Adds helper method to files_controller
Browse files Browse the repository at this point in the history
  • Loading branch information
HazelGrant committed Mar 28, 2024
1 parent 3440282 commit 234d239
Showing 1 changed file with 14 additions and 0 deletions.
14 changes: 14 additions & 0 deletions apps/dashboard/app/controllers/files_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -181,6 +181,20 @@ def edit

private

def send_stream(filename:, disposition: "attachment", type: nil)
response.headers["Content-Type"] =
(type.is_a?(Symbol) ? Mime[type].to_s : type) ||
Mime::Type.lookup_by_extension(File.extname(filename).downcase.delete("."))&.to_s ||
"application/octet-stream"

response.headers["Content-Disposition"] =
ActionDispatch::Http::ContentDisposition.format(disposition: disposition, filename: filename)

yield response.stream
ensure
response.stream.close
end

# set these headers to nil so that we (Rails) will read files
# off of disk instead of nginx.
def strip_sendfile_headers
Expand Down

0 comments on commit 234d239

Please sign in to comment.