mirror of
https://github.com/discourse/discourse.git
synced 2025-05-28 13:51:18 +08:00
FIX: Add attachment content-disposition for all non-image files (#10058)
This will make it so the original filename is used when downloading all non-image files, bringing S3Store into line with the to_s3 migration and local storage. Video and audio files will still stream correctly in HTML players as well. See https://meta.discourse.org/t/cannot-download-non-image-media-files-original-filenames-lost-when-uploaded-to-s3/152797 for a lot of extra context.
This commit is contained in:
@ -53,8 +53,14 @@ module FileStore
|
||||
cache_control: 'max-age=31556952, public, immutable',
|
||||
content_type: opts[:content_type].presence || MiniMime.lookup_by_filename(filename)&.content_type
|
||||
}
|
||||
# add a "content disposition" header for "attachments"
|
||||
options[:content_disposition] = "attachment; filename=\"#{filename}\"" unless FileHelper.is_supported_media?(filename)
|
||||
|
||||
# add a "content disposition: attachment" header with the original filename
|
||||
# for everything but images. audio and video will still stream correctly in
|
||||
# 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}\""
|
||||
end
|
||||
|
||||
path.prepend(File.join(upload_path, "/")) if Rails.configuration.multisite
|
||||
|
||||
|
Reference in New Issue
Block a user