diff Sphinx/source/plugins/python/storage-area.py @ 748:a296fe06fd86

Implementing a custom storage area in Python
author Sebastien Jodogne <s.jodogne@gmail.com>
date Thu, 12 Aug 2021 17:51:54 +0200
parents
children
line wrap: on
line diff
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/Sphinx/source/plugins/python/storage-area.py	Thu Aug 12 17:51:54 2021 +0200
@@ -0,0 +1,19 @@
+import orthanc
+import os
+
+def GetPath(uuid, contentType):
+    # Returns the path where to store the given attachment
+    return 'attachment-%d-%s' % (contentType, uuid)
+
+def OnCreate(uuid, contentType, data):
+    with open(GetPath(uuid, contentType), 'wb') as f:
+        f.write(data)
+
+def OnRead(uuid, contentType):
+    with open(GetPath(uuid, contentType), 'rb') as f:
+        return f.read()
+
+def OnRemove(uuid, contentType):
+    os.remove(GetPath(uuid, contentType))
+
+orthanc.RegisterStorageArea(OnCreate, OnRead, OnRemove)