orthancFileBrowser.py 1.1 KB

1234567891011121314151617181920212223242526272829303132333435363738
  1. import urllib3
  2. import shutil
  3. class orthancFileBrowser:
  4. def __init__(self,net):
  5. self.net=net
  6. def getZip(self,retrieveLevel, dataId, path):
  7. url=self.net.getCoreURL()
  8. url+="/"+retrieveLevel+"/"+dataId+"/archive"
  9. print("Using: {}".format(url))
  10. response=self.net.get(url,binary=True)
  11. with open(path,'wb') as out_file:
  12. shutil.copyfileobj(response,out_file)
  13. response.release_conn()
  14. #response.data is a byte array -> is the same as file
  15. def getInstance(self, instanceId, localFile):
  16. url=self.net.getCoreURL()
  17. url+='/instances/'+instanceId+'/file'
  18. print('Using {}'.format(url))
  19. response=self.net.get(url,binary=True)
  20. with open(localFile,'wb') as out_file:
  21. shutil.copyfileobj(response,out_file)
  22. response.release_conn()
  23. def upload(self,path):
  24. url=self.net.getCoreURL()
  25. url+="/instances"
  26. with open(path,'rb') as f:
  27. response=self.net.post(url,"octet-stream", f.read())
  28. print(response.data)