comparison Sphinx/source/users/advanced-rest.rst @ 297:64d1ddab8246

Improved PDF creation Pwsh snippet + added Dicom instance upload example with Pwsh + added Windows docker script to generate book
author Benjamin Golinvaux <bgo@osimis.io>
date Mon, 20 Jan 2020 14:43:22 +0100
parents 6cbcdb965ad3
children c13431b26e55
comparison
equal deleted inserted replaced
295:b4b9ceebe64d 297:64d1ddab8246
162 PDF files. The ``/tools/create-dicom`` URI can be used to upload a PDF 162 PDF files. The ``/tools/create-dicom`` URI can be used to upload a PDF
163 file to Orthanc. The following scripts perform such a *DICOM-ization*; 163 file to Orthanc. The following scripts perform such a *DICOM-ization*;
164 They convert the ``HelloWorld2.pdf`` file to base64, then perform a 164 They convert the ``HelloWorld2.pdf`` file to base64, then perform a
165 ``POST`` request with JSON data containing the converted payload. 165 ``POST`` request with JSON data containing the converted payload.
166 166
167 .. highlight:: bash 167 Using bash:
168 168
169 Using bash:: 169 .. code-block:: bash
170 170
171 # create the json data, with the BASE64 data embedded in it 171 # create the json data, with the BASE64 data embedded in it
172 (echo -n '{"Tags" : {"PatientName" : "Benjamino", "Modality" : "CT"},"Content" : "data:application/pdf;base64,'; base64 HelloWorld2.pdf; echo '"}') > /tmp/foo 172 (echo -n '{"Tags" : {"PatientName" : "Benjamino", "Modality" : "CT"},"Content" : "data:application/pdf;base64,'; base64 HelloWorld2.pdf; echo '"}') > /tmp/foo
173 173
174 # upload it to Orthanc 174 # upload it to Orthanc
175 cat /tmp/foo | curl -H "Content-Type: application/json" -d @- http://localhost:8042/tools/create-dicom 175 cat /tmp/foo | curl -H "Content-Type: application/json" -d @- http://localhost:8042/tools/create-dicom
176 176
177 .. highlight:: powershell 177
178 178 Using powershell:
179 Using Powershell:: 179
180 .. code-block:: perl
180 181
181 # create the BASE64 string data 182 # create the BASE64 string data
182 $fileInBase64 = $([Convert]::ToBase64String((gc -Path "HelloWorld2.pdf" -Encoding Byte))) 183 $fileInBase64 = $([Convert]::ToBase64String((gc -Path "HelloWorld2.pdf" -Encoding Byte)))
183 184
184 # create the json data 185 # create the json data
185 $params = @{Tags = @{PatientName = "Benjamino";Modality = "CT"};Content= "data:application/pdf;base64,$fileInBase64"} 186 $params = @{Tags = @{PatientName = "Benjamino";Modality = "CT"};Content= "data:application/pdf;base64,$fileInBase64"}
186 187
187 # upload it to Orthanc and convert the result to json 188 # disabling progress bar tremendously increases the Invoke-RestMethod call
188 $reply = Invoke-WebRequest -Uri http://localhost:8042/tools/create-dicom -Method POST -Body ($params|ConvertTo-Json) -ContentType "application/json" | ConvertFrom-Json 189 $ProgressPreference = 'SilentlyContinue'
190
191 # upload it to Orthanc
192 $reply = Invoke-RestMethod http://localhost:8042/tools/create-dicom -Method POST -Body ($params|ConvertTo-Json) -ContentType 'application/json'
189 193
190 # display the result 194 # display the result
191 Write-Host "The instance can be retrieved in PDF at http://localhost:8042$($reply.Path)/pdf" 195 Write-Host "The instance can be retrieved in PDF at http://localhost:8042$($reply.Path)/pdf"
192 196
193 Please note that the ``/tools/create-dicom`` API call will return the 197 Please note that the ``/tools/create-dicom`` API call will return the