From 9a39f3776d66dd30cdcc38159e90e9c7639b6027 Mon Sep 17 00:00:00 2001 From: MarcZierle Date: Wed, 22 Jun 2022 12:03:04 +0200 Subject: [PATCH] fix s3 uploads arguments --- photo_log/tasks.py | 30 ++++++++++++++++++++++++------ 1 file changed, 24 insertions(+), 6 deletions(-) diff --git a/photo_log/tasks.py b/photo_log/tasks.py index 7ba8032..aad8eef 100644 --- a/photo_log/tasks.py +++ b/photo_log/tasks.py @@ -66,7 +66,7 @@ def download_s3_file(folder_path, s3_file_path, bucket): @shared_task -def upload_s3_file(file_path, s3_file_path, bucket): +def upload_s3_file(file_path, s3_file_path, bucket, content_type='application/octet-stream'): """ Uploads a file to a S3 object storages. :param file_path Path on local disk where the is saved. @@ -82,7 +82,15 @@ def upload_s3_file(file_path, s3_file_path, bucket): ) client = s3_resource.meta.client - client.upload_file(file_path, bucket, s3_file_path) + client.upload_file( + file_path, + bucket, + s3_file_path, + ExtraArgs={ + 'ContentDisposition': 'inline', + 'ContentType': content_type, + } + ) @shared_task @@ -216,7 +224,8 @@ def max_resize_image_chain(full_file_name, max_width, work_folder_name=uuid4()): upload_s3_file.si( local_file, full_file_name, - bucket + bucket, + content_type='image/png' ), delete_folder.si( folder @@ -250,12 +259,19 @@ def crop_image_bbox_chain(photo_pk, full_file_name, bbox, rotate_angle, cropped_ upload_s3_file.si( local_file, s3_upload_name, - bucket + bucket, + content_type='image/png' ), update_model_field.si(# photo_log.Photo(pk=photo_pk).cropped_image = s3_upload_name 'photo_log', 'Photo', photo_pk, 'cropped_image', s3_upload_name ), + notify_client.si( + description='update_photo', + content={ + 'id': photo_pk + } + ), delete_folder.si( folder ), @@ -286,7 +302,8 @@ def crop_image_auto_chain(photo_pk, full_file_name, cropped_img_name=None, work_ upload_s3_file.si( local_file, s3_upload_name, - bucket + bucket, + content_type='image/png' ), update_model_field.si(# photo_log.Photo(pk=photo_pk).cropped_image = s3_upload_name 'photo_log', 'Photo', photo_pk, @@ -390,7 +407,8 @@ def generate_photo_log_chain(photo_log_id, work_folder_name=uuid4()): upload_s3_file.si( pdf_file, pdf_s3_path, - bucket + bucket, + content_type='application/pdf' ), update_model_field.si( 'photo_log', 'PhotoLog', photo_log.id,