mirror of
https://github.com/discourse/discourse.git
synced 2025-06-01 05:53:52 +08:00
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:
@ -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
|
||||
|
@ -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
|
||||
|
Reference in New Issue
Block a user