diff --git a/attachment_s3/models/ir_attachment.py b/attachment_s3/models/ir_attachment.py index e573b98b..b39f60e0 100644 --- a/attachment_s3/models/ir_attachment.py +++ b/attachment_s3/models/ir_attachment.py @@ -181,6 +181,7 @@ def _store_file_read(self, fname, bin_size=False): @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') if location == 's3': bucket = self._get_s3_bucket() obj = bucket.Object(key=key) @@ -189,7 +190,10 @@ def _store_file_write(self, key, bin_data): 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( diff --git a/base_attachment_object_storage/models/ir_attachment.py b/base_attachment_object_storage/models/ir_attachment.py index 0a3ecfa2..1ef2a8ae 100644 --- a/base_attachment_object_storage/models/ir_attachment.py +++ b/base_attachment_object_storage/models/ir_attachment.py @@ -164,6 +164,10 @@ def _store_in_db_instead_of_object_storage(self): 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