From 1bf385e35f04aad8121d685c42e46a3829130508 Mon Sep 17 00:00:00 2001 From: Tim Abbott Date: Tue, 6 Nov 2018 13:03:14 -0800 Subject: [PATCH] import: Avoid sending a content-type of None to S3. The previous logic was incorrect, in that if `content_type` was set to None (which happens with Slack/HipChat export, among other things), then we wouldn't run the `guess_type` logic to auto-detect the Content-Type to send to S3. --- zerver/lib/import_realm.py | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/zerver/lib/import_realm.py b/zerver/lib/import_realm.py index 4bba233b24..8876c23174 100644 --- a/zerver/lib/import_realm.py +++ b/zerver/lib/import_realm.py @@ -603,7 +603,9 @@ def import_uploads_s3(bucket_name: str, import_dir: Path, processing_avatars: bo key.set_metadata("realm_id", str(record['realm_id'])) # Zulip exports will always have a content-type, but third-party exports might not. - content_type = record.get("content_type", guess_type(record['s3_path'])[0]) + content_type = record.get("content_type") + if content_type is None: + content_type = guess_type(record['s3_path'])[0] headers = {'Content-Type': content_type} key.set_contents_from_filename(os.path.join(import_dir, record['path']), headers=headers)