Mercurial > hg > orthanc-dicomweb
changeset 287:8d0c90e8b374 refactoring
use chunked transfers in SendStow.py sample script
author | Sebastien Jodogne <s.jodogne@gmail.com> |
---|---|
date | Fri, 07 Jun 2019 17:18:27 +0200 |
parents | 031f34284a78 |
children | 29ca4d7ac067 |
files | Plugin/Plugin.cpp Resources/Samples/Python/SendStow.py |
diffstat | 2 files changed, 30 insertions(+), 3 deletions(-) [+] |
line wrap: on
line diff
--- a/Plugin/Plugin.cpp Fri Jun 07 16:03:50 2019 +0200 +++ b/Plugin/Plugin.cpp Fri Jun 07 17:18:27 2019 +0200 @@ -231,6 +231,13 @@ const std::map<std::string, std::string>& headers) { printf("new handler: [%s] [%s]\n", contentType.c_str(), subType.c_str()); + + for (std::map<std::string, std::string>::const_iterator + it = headers.begin(); it != headers.end(); ++it) + { + printf(" header: [%s] = [%s]\n", it->first.c_str(), it->second.c_str()); + } + return new Handler(count_++); } };
--- a/Resources/Samples/Python/SendStow.py Fri Jun 07 16:03:50 2019 +0200 +++ b/Resources/Samples/Python/SendStow.py Fri Jun 07 17:18:27 2019 +0200 @@ -58,11 +58,31 @@ # Closing boundary body += bytearray('--%s--' % boundary, 'ascii') -# Do the HTTP POST request to the STOW-RS server -r = requests.post(URL, data=body, headers= { +headers = { 'Content-Type' : 'multipart/related; type=application/dicom; boundary=%s' % boundary, 'Accept' : 'application/json', -}) + } + +# Do the HTTP POST request to the STOW-RS server +if False: + # Don't use chunked transfer (this code was in use in DICOMweb plugin <= 0.6) + r = requests.post(URL, data=body, headers=headers) +else: + # Use chunked transfer + # https://2.python-requests.org/en/master/user/advanced/#chunk-encoded-requests + def gen(): + chunkSize = 1024 * 1024 + + l = len(body) / chunkSize + for i in range(l): + pos = i * chunkSize + yield body[pos : pos + chunkSize] + + if len(body) % chunkSize != 0: + yield body[l * chunkSize :] + + r = requests.post(URL, data=gen(), headers=headers) + j = json.loads(r.text)