view Sphinx/source/plugins/python/extend-api-with-streaming.py @ 1150:84d5e5f3c670

Added tag Orthanc-1.12.7 for changeset a23a5e08f3b4
author Sebastien Jodogne <s.jodogne@gmail.com>
date Mon, 07 Apr 2025 13:01:12 +0200
parents 9c063c145c0e
children 730fd5c08b0b
line wrap: on
line source

import orthanc
import requests

TOKEN = orthanc.GenerateRestApiAuthorizationToken()

def OnRestArchive(output, uri, **request):
    study_id = request['groups'][0]
    print(f"Accessing archive for study: {study_id}")
    
    # put your business logic here

    with requests.get(f"http://localhost:8043/studies/{study_id}/archive", headers = { 'Authorization' : TOKEN }, stream = True) as r:
        output.StartStreamAnswer('application/zip')

        for buffer in r.iter_content(16*1024, False):
            print(len(buffer))
            output.SendStreamChunk(buffer)
    

orthanc.RegisterRestCallback('/studies/(.*)/my-archive', OnRestArchive)