add conditionnal mimetype upload file s3

This commit is contained in:
cyrilmanuel committed 2023-01-26 11:59:45 +01:00
1 parent 6dd6d71807
commit 7e785507f7
2 files changed
+9 -1

No files matched your search

+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(
@@ -164,6 +164,10 @@ class IrAttachment(models.Model):
return len(bin_data) <= limit
return False
def _get_datas_related_values(self, data, mimetype):
self=self.with_context(mimetype=mimetype)
return super(IrAttachment, self)._get_datas_related_values(data, mimetype)
def _inverse_datas(self):
# override in order to store files that need fast access,
# we keep them in the database instead of the object storage
Reference in new issue
Block a user
Blocking a user prevents them from interacting with repositories, such as opening or commenting on pull requests or issues. Learn more about blocking a user.