FIX: Use ActionDispatch::Http::ContentDisposition for uploads content-disposition (#10108)

See https://meta.discourse.org/t/broken-pipe-error-when-uploading-to-a-s3-clone-a-pdf-with-a-name-containing-e-i-etc/155414

When setting content-disposition for attachment, use the ContentDisposition class to format it. This handles filenames with weird characters and localization (accented characters) correctly.
This commit is contained in:
Martin Brennan
2020-06-23 17:10:56 +10:00
committed by GitHub
parent 97f045d06a
commit e92909aa77
4 changed files with 10 additions and 7 deletions

View File

@ -59,7 +59,9 @@ module FileStore
# HTML players, and when a direct link is provided to any file but an image
# it will download correctly in the browser.
if !FileHelper.is_supported_image?(filename)
options[:content_disposition] = "attachment; filename=\"#{filename}\""
options[:content_disposition] = ActionDispatch::Http::ContentDisposition.format(
disposition: "attachment", filename: filename
)
end
path.prepend(File.join(upload_path, "/")) if Rails.configuration.multisite

View File

@ -224,8 +224,9 @@ module FileStore
upload = Upload.find_by(url: "/#{file}")
if upload&.original_filename
options[:content_disposition] =
%Q{attachment; filename="#{upload.original_filename}"}
options[:content_disposition] = ActionDispatch::Http::ContentDisposition.format(
disposition: "attachment", filename: upload.original_filename
)
end
if upload&.secure