changeset 1152:730fd5c08b0b

python streaming
author Alain Mazy <am@orthanc.team>
date Thu, 24 Apr 2025 14:40:39 +0200 (4 days ago)
parents ebc0c3323c98
children ca8698332aac
files Sphinx/source/faq/how-do-you-spell-orthanc.rst Sphinx/source/plugins/python/extend-api-with-streaming.py
diffstat 2 files changed, 4 insertions(+), 0 deletions(-) [+]
line wrap: on
line diff
--- a/Sphinx/source/faq/how-do-you-spell-orthanc.rst	Mon Apr 14 08:57:19 2025 +0200
+++ b/Sphinx/source/faq/how-do-you-spell-orthanc.rst	Thu Apr 24 14:40:39 2025 +0200
@@ -14,6 +14,7 @@
 - ORTHAC
 - ORTHAN
 - ORTHANK
+- ORTHANS
 - ORTHNAC
 - ORTHONC
 - ORTNAC
--- a/Sphinx/source/plugins/python/extend-api-with-streaming.py	Mon Apr 14 08:57:19 2025 +0200
+++ b/Sphinx/source/plugins/python/extend-api-with-streaming.py	Thu Apr 24 14:40:39 2025 +0200
@@ -10,6 +10,9 @@
     # put your business logic here
 
     with requests.get(f"http://localhost:8043/studies/{study_id}/archive", headers = { 'Authorization' : TOKEN }, stream = True) as r:
+        # Note, it is important to set the headers before calling StartStreamAnswer, once the answer has started to stream, it is to late to modify headers
+        output.SetHttpHeader('Content-Disposition', 'filename=my-custom-name.zip')
+
         output.StartStreamAnswer('application/zip')
 
         for buffer in r.iter_content(16*1024, False):