FIX: Make sure S3 object headers are preserved on copy (#14302)

When copying an existing upload stub temporary object
on S3 to its final destination we were not copying across
its additional headers such as content-disposition and
cache-control, which led to issues like attachments not
downloading with their original filename when clicking
the download links in posts.

This is because the metadata_directive = REPLACE option
was not being passed to object.copy_from(), so only the
source object's headers were being used. Added an option
for apply_metadata_to_destination to apply this option
conditionally, because we may not always want to replace
this metadata, but we definitely do when copying a temporary
upload.
This commit is contained in:
Martin Brennan
2021-09-10 12:59:51 +10:00
committed by GitHub
parent f3df5834b6
commit 0d809197aa
4 changed files with 97 additions and 1 deletions

View File

@ -98,6 +98,7 @@ module FileStore
# if this fails, it will throw an exception
if opts[:move_existing] && opts[:existing_external_upload_key]
original_path = opts[:existing_external_upload_key]
options[:apply_metadata_to_destination] = true
path, etag = s3_helper.copy(
original_path,
path,