Mercurial > hg > orthanc-book
comparison Sphinx/source/users/advanced-rest.rst @ 225:ced9dbf86de8
Added tutorial that shows how to upload and retrieve PDF files using the REST API
author | Benjamin Golinvaux <bgo@osimis.io> |
---|---|
date | Wed, 06 Mar 2019 08:13:01 +0100 |
parents | 02399e86f046 |
children | eaae8d630277 |
comparison
equal
deleted
inserted
replaced
224:02399e86f046 | 225:ced9dbf86de8 |
---|---|
1 .. _rest-advanced: | 1 .. _rest-advanced: |
2 .. highlight:: bash | |
2 | 3 |
3 Advanced features of the REST API | 4 Advanced features of the REST API |
4 ================================= | 5 ================================= |
5 | 6 |
6 .. contents:: | 7 .. contents:: |
65 .. _pdf: | 66 .. _pdf: |
66 | 67 |
67 PDF | 68 PDF |
68 --- | 69 --- |
69 | 70 |
70 TODO | 71 Among many different types of data, DICOM files can be used to store PDF files. The ``create-dicom`` API route can be used to upload a PDF file to Orthanc. |
72 | |
73 The following scripts perform such a *dicomization* ; they convert the ``HelloWorld2.pdf`` file to base64, then perform a ``POST`` request with JSON data containing the converted payload. | |
74 | |
75 Using bash:: | |
76 | |
77 # create the json data, with the BASE64 data embedded in it | |
78 (echo -n '{"Tags" : {"PatientName" : "Benjamino", "Modality" : "CT"},"Content" : "data:application/pdf;base64,'; base64 HelloWorld2.pdf; echo '"}') > /tmp/foo | |
79 | |
80 # upload it to Orthanc | |
81 cat /tmp/foo | curl -H "Content-Type: application/json" -d @- http://localhost:8042/tools/create-dicom | |
82 | |
83 Using Powershell:: | |
84 | |
85 # create the BASE64 string data | |
86 $fileInBase64 = $([Convert]::ToBase64String((gc -Path "HelloWorld2.pdf" -Encoding Byte))) | |
87 | |
88 # create the json data | |
89 $params = @{Tags = @{PatientName = "Benjamino";Modality = "CT"};Content= "data:application/pdf;base64,$fileInBase64"} | |
90 | |
91 # upload it to Orthanc and convert the result to json | |
92 $reply = Invoke-WebRequest -Uri http://localhost:8042/tools/create-dicom -Method POST -Body ($params|ConvertTo-Json) -ContentType "application/json" | ConvertFrom-Json | |
93 | |
94 # display the result | |
95 Write-Host "The instance can be retrieved in PDF at http://localhost:8042$($reply.Path)/pdf" | |
96 | |
97 Please note that the `create-dicom` API call will return the Orthanc instance ID of the newly created DICOM resource. You can then use the ``http://localhost:8042/<INSTANCE-ID>/pdf`` route to request the stored file as PDF. |