diff --git a/attachment_swift/tests/test_mock_swift_api.py b/attachment_swift/tests/test_mock_swift_api.py index 9bea70d..205e284 100644 --- a/attachment_swift/tests/test_mock_swift_api.py +++ b/attachment_swift/tests/test_mock_swift_api.py @@ -2,6 +2,7 @@ # Copyright 2017 Camptocamp SA # License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html) +import base64 import os from mock import patch @@ -46,7 +47,7 @@ class TestAttachmentSwift(TestIrAttachment): os.environ['SWIFT_WRITE_CONTAINER'] = 'my_container' container = os.environ.get('SWIFT_WRITE_CONTAINER') attachment = self.Attachment - bin_data = self.blob1_b64.decode('base64') + bin_data = base64.b64decode(self.blob1_b64) with patch('swiftclient.client.Connection') as MockConnection: conn = MockConnection.return_value attachment.create({'name': 'a5', 'datas': self.blob1_b64}) diff --git a/base_attachment_object_storage/models/ir_attachment.py b/base_attachment_object_storage/models/ir_attachment.py index 9063cc6..64f800a 100644 --- a/base_attachment_object_storage/models/ir_attachment.py +++ b/base_attachment_object_storage/models/ir_attachment.py @@ -3,6 +3,7 @@ # License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html) +import base64 import logging import os import psycopg2 @@ -61,7 +62,7 @@ class IrAttachment(models.Model): if location in self._get_stores() and attach._save_in_db_anyway(): # compute the fields that depend on datas value = attach.datas - bin_data = value and value.decode('base64') or '' + bin_data = base64.b64decode(value) if value else '' vals = { 'file_size': len(bin_data), 'checksum': self._compute_checksum(bin_data), @@ -107,7 +108,7 @@ class IrAttachment(models.Model): @api.model def _file_write(self, value, checksum): if self._storage() in self._get_stores(): - bin_data = value.decode('base64') + bin_data = base64.b64decode(value) key = self._compute_checksum(bin_data) filename = self._store_file_write(key, bin_data) else: