add conditionnal mimetype upload file s3

This commit is contained in:
cyrilmanuel
2023-01-26 11:59:45 +01:00
parent 6dd6d71807
commit 7e785507f7
2 changed files with 9 additions and 1 deletions
+5 -1
View File
@@ -181,6 +181,7 @@ class IrAttachment(models.Model):
@api.model
def _store_file_write(self, key, bin_data):
location = self.env.context.get('storage_location') or self._storage()
mimetype = self.env.context.get('mimetype') or self.mimetype
if location == 's3':
bucket = self._get_s3_bucket()
obj = bucket.Object(key=key)
@@ -189,7 +190,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={'ContentType': mimetype})
else:
obj.upload_fileobj(file)
except ClientError as error:
# log verbose error from s3, return short message for user
_logger.exception(