add conditionnal mimetype upload file s3

This commit is contained in:
cyrilmanuel
2023-01-25 11:30:13 +01:00
parent 6dd6d71807
commit fa8a96f0d3
+5 -2
View File
@@ -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(