mirror of
https://github.com/camptocamp/odoo-cloud-platform.git
synced 2026-06-24 08:47:40 +00:00
add conditionnal mimetype upload file s3
This commit is contained in:
@@ -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(
|
||||
|
||||
Reference in New Issue
Block a user