From fa8a96f0d32c4279e693113eb7415d4dc4bf63d1 Mon Sep 17 00:00:00 2001 From: cyrilmanuel Date: Wed, 25 Jan 2023 11:30:13 +0100 Subject: [PATCH] add conditionnal mimetype upload file s3 --- attachment_s3/models/ir_attachment.py | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/attachment_s3/models/ir_attachment.py b/attachment_s3/models/ir_attachment.py index e573b98..de78636 100644 --- a/attachment_s3/models/ir_attachment.py +++ b/attachment_s3/models/ir_attachment.py @@ -179,7 +179,7 @@ class IrAttachment(models.Model): return super(IrAttachment, self)._store_file_read(fname, bin_size) @api.model - def _store_file_write(self, key, bin_data): + def _store_file_write(self, key, bin_data, mimetype=False): location = self.env.context.get('storage_location') or self._storage() if location == 's3': bucket = self._get_s3_bucket() @@ -189,7 +189,10 @@ class IrAttachment(models.Model): file.seek(0) filename = 's3://%s/%s' % (bucket.name, key) try: - obj.upload_fileobj(file) + if mimetype: + obj.upload_fileobj(file, ExtraArgs={'Metadata': {'ContentType': mimetype}}) + else: + obj.upload_fileobj(file) except ClientError as error: # log verbose error from s3, return short message for user _logger.exception(