mirror of
https://github.com/discourse/discourse.git
synced 2025-05-30 07:11:34 +08:00
FIX: Include original filename in s3 uploads even if not attachment (#30789)
Related: https://github.com/discourse/discourse/pull/30535 In the PR above, the [content-disposition header](https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Content-Disposition) was removed for all non-svg files due to the "attachment" keyword added to them, causing files to be downloaded instead of opening in a new tab when requested. When removing that, it also removed the filename attribute attached to s3 uploads. After some testing, it turns out that `filename` is also respected when next to `inline`, despite it not being obvious [in docs](https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Content-Disposition#syntax). This commit adds inline+filename so that users can still download files and have filenames be respected instead of using the s3 hash. ```http <!-- mdn docs --> Content-Disposition: inline Content-Disposition: attachment Content-Disposition: attachment; filename="file name.jpg" Content-Disposition: attachment; filename*=UTF-8''file%20name.jpg <!-- this actually works too --> Content-Disposition: inline; filename="file name.jpg" ```
This commit is contained in:
@ -97,12 +97,10 @@ module FileStore
|
||||
# Only add a "content disposition: attachment" header for svgs
|
||||
# see https://github.com/discourse/discourse/commit/31e31ef44973dc4daaee2f010d71588ea5873b53.
|
||||
# Adding this header for all files would break the ability to view attachments in the browser
|
||||
if FileHelper.is_svg?(filename)
|
||||
options[:content_disposition] = ActionDispatch::Http::ContentDisposition.format(
|
||||
disposition: "attachment",
|
||||
filename: filename,
|
||||
)
|
||||
end
|
||||
options[:content_disposition] = ActionDispatch::Http::ContentDisposition.format(
|
||||
disposition: FileHelper.is_svg?(filename) ? "attachment" : "inline",
|
||||
filename: filename,
|
||||
)
|
||||
|
||||
path.prepend(File.join(upload_path, "/")) if Rails.configuration.multisite
|
||||
|
||||
|
Reference in New Issue
Block a user