models_3.py 873 B

12345678910111213141516171819
  1. def _file_write(self, value, checksum):
  2. storage = self._storage()
  3. if storage[:5] == 's3://':
  4. access_key_id, secret_key, bucket_name, do_space_url = s3_helper.parse_bucket_url(
  5. storage)
  6. s3 = s3_helper.get_resource(
  7. access_key_id, secret_key, do_space_url)
  8. s3_bucket = self._connect_to_S3_bucket(s3, bucket_name)
  9. bin_value = base64.b64decode(value)
  10. fname = hashlib.sha1(bin_value).hexdigest()
  11. if encryption_enabled:
  12. s3.Object(s3_bucket.name, fname).put(Body=bin_value, ServerSideEncryption='AES256')
  13. else:
  14. s3.Object(s3_bucket.name, fname).put(Body=bin_value)
  15. else: # falling back on Odoo's local filestore
  16. fname = super(S3Attachment, self)._file_write(value, checksum)
  17. return fname