comparison 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
comparison
equal deleted inserted replaced
747:56d48f6e52cc 748:a296fe06fd86
1 import orthanc
2 import os
3
4 def GetPath(uuid, contentType):
5 # Returns the path where to store the given attachment
6 return 'attachment-%d-%s' % (contentType, uuid)
7
8 def OnCreate(uuid, contentType, data):
9 with open(GetPath(uuid, contentType), 'wb') as f:
10 f.write(data)
11
12 def OnRead(uuid, contentType):
13 with open(GetPath(uuid, contentType), 'rb') as f:
14 return f.read()
15
16 def OnRemove(uuid, contentType):
17 os.remove(GetPath(uuid, contentType))
18
19 orthanc.RegisterStorageArea(OnCreate, OnRead, OnRemove)