Browse Source

Adding uploadFile

Andrej 4 years ago
parent
commit
7453f44a71
2 changed files with 41 additions and 0 deletions
  1. 8 0
      orthancFileBrowser.py
  2. 33 0
      pythonScripts/testUpload.py

+ 8 - 0
orthancFileBrowser.py

@@ -10,9 +10,17 @@ class orthancFileBrowser:
     def getZip(self,retrieveLevel, dataId, path):
         url=self.net.getCoreURL()
         url+="/"+retrieveLevel+"/"+dataId+"/archive";
+        print("Using: {}".format(url))
         response=self.net.get(url,binary=True);
         with open(path,'wb') as out_file:
             shutil.copyfileobj(response,out_file)
         response.release_conn()
         #response.data is a byte array -> is the same as file
 
+    def upload(self,path):
+        url=self.net.getCoreURL()
+        url+="/instances"
+        with open(path,'rb') as f:
+            response=self.net.post(url,"octet-stream", f.read())
+        print(response.data)
+

+ 33 - 0
pythonScripts/testUpload.py

@@ -0,0 +1,33 @@
+import os
+import json
+import re
+import subprocess
+#import nibabel
+import shutil
+import sys
+import pydicom
+
+shome=os.path.expanduser('~studen')
+
+sys.path.insert(1,shome+'/software/src/orthancInterface')
+import orthancInterface
+import orthancFileBrowser
+
+fhome=os.path.expanduser('~')
+fconfig=os.path.join(fhome,'.labkey','network.json')
+
+onet=orthancInterface.orthancInterface()
+onet.init(fconfig)
+ofb=orthancFileBrowser.orthancFileBrowser(onet)
+
+uploadDir=os.path.join(fhome,'temp','testFiles')
+
+files=os.listdir(uploadDir)
+
+for f in files:
+    fg=os.path.join(uploadDir,f)
+    print(fg)
+    ofb.upload(fg)
+
+print("Done")
+