From 74ff77d36652ccd42b2f8eb67fdf618ebb0bf8ae Mon Sep 17 00:00:00 2001 From: Tim Abbott Date: Sat, 29 Dec 2018 22:13:11 -0800 Subject: [PATCH] import: Always set a valid content-type for S3 backend. The octet-stream content type is potentially under-specified, but it's better than potentially submitting None and increases consistency of this part of the codebase. --- zerver/lib/import_realm.py | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/zerver/lib/import_realm.py b/zerver/lib/import_realm.py index 42fa1e83f0..57e4d774dc 100644 --- a/zerver/lib/import_realm.py +++ b/zerver/lib/import_realm.py @@ -601,6 +601,12 @@ def import_uploads(import_dir: Path, processing_avatars: bool=False, content_type = record.get("content_type") if content_type is None: content_type = guess_type(record['s3_path'])[0] + if content_type is None: + # This is the default for unknown data. Note that + # for `.original` files, this is the value we'll + # set; that is OK, because those are never served + # directly anyway. + content_type = 'application/octet-stream' headers = {'Content-Type': content_type} # type: Dict[str, Any] key.set_contents_from_filename(os.path.join(import_dir, record['path']), headers=headers)