[PATCH 4 of 4] [storages] try to handle the BFSS case (WIP)

Arthur Lutz arthur.lutz at logilab.fr
Fri Sep 20 14:42:28 CEST 2019


# HG changeset patch
# User Arthur Lutz <arthur.lutz at logilab.fr>
# Date 1568983104 -7200
#      Fri Sep 20 14:38:24 2019 +0200
# Node ID a4d786db0682f22e6279975531cf90244cb18a02
# Parent  bacb587fcac6fef524fff9026113f8407fa0e580
# EXP-Topic custom-s3-endpoint
[storages] try to handle the BFSS case (WIP)

diff -r bacb587fcac6 -r a4d786db0682 cubicweb_s3storage/storages.py
--- a/cubicweb_s3storage/storages.py	Fri Sep 20 14:37:00 2019 +0200
+++ b/cubicweb_s3storage/storages.py	Fri Sep 20 14:38:24 2019 +0200
@@ -56,6 +56,18 @@
     def entity_added(self, entity, attr):
         """an entity using this storage for attr has been added"""
         binary = entity.cw_edited.pop(attr)
+        # if the file is BFSS then store the content not the filename
+        try:
+            entity._cw.repo.system_source.storage(entity.cw_etype, attr)
+            # test storage if BFSS ?
+        # TODO should be more specific in cubicweb native.py
+        except:  # noqa - "no custom storage set"
+            # TODO - there must be a better way to do this
+            if binary.read().startswith(b'/'):
+                binary.seek(0)
+                binary = open(binary.read(), "rb")
+            else:
+                binary.seek(0)
         if binary is not None:
             key = self.get_s3_key(entity, attr)
             # bytes storage used to store S3's object key



More information about the cubicweb-devel mailing list