123456789101112131415161718192021222324252627282930313233343536373839 |
- import urllib3
- import shutil
- class orthancFileBrowser:
- def __init__(self,net):
- self.net=net
- def getZip(self,retrieveLevel, dataId, path, mode='archive'):
- #mode can be archive(ZIP,default) or media (DICOMDIR)
- url=self.net.getCoreURL()
- url+="/"+retrieveLevel+"/"+dataId+"/"+mode
- 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 getInstance(self, instanceId, localFile):
- url=self.net.getCoreURL()
- url+='/instances/'+instanceId+'/file'
- print('Using {}'.format(url))
- response=self.net.get(url,binary=True)
- with open(localFile,'wb') as out_file:
- shutil.copyfileobj(response,out_file)
- response.release_conn()
- 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)
-
|