Hi Authors,
I am developing plugin in C++ which using internal OrthancPlugins::RestApiPost. What I want to achieve is to send multiple dicom instances via route “/instances” to internal API. But I dont find any signature from OrthancPlugins::RestApiPost to send form-data.
This is the code I tried, but orthanc denied
std::vectorstd::string paths = {“00001.dcm”, “00002.dcm”};
for (const auto& path : paths) {
std::string dicom;
Orthanc::SystemToolbox::ReadFile(dicom, path);
formData.append(dicom);
}
Json::Value upload;
OrthancPlugins::RestApiPost(upload, “/instances”, formData, false);
I1203 10:53:27.944115 OrthancPlugins.cpp:2755] (plugins) Plugin making REST POST call on URI /instances (built-in API) I1203 10:53:27.944187 OrthancRestApi.cpp:173] (http) Receiving a DICOM file of 380876717 bytes through HTTP E: DcmElement: Unknown Tag & Data (225b,755c) larger (808464432) than remaining bytes (380876709) in file, premature end of stream E1203 10:53:28.146568 OrthancException.cpp:57] Bad file format: Cannot parse an invalid DICOM file (size: 380876717 bytes) E1203 10:53:28.159781 PluginsManager.cpp:197] Exception while invoking plugin service 3002: Bad file format E1203 10:53:28.182317 PluginsErrorDictionary.cpp:111] Exception inside the plugin engine: Bad file format
Can you please help what is the right way ? Thanks
Hello,
POST on “/instances” only accepts one DICOM instance or one ZIP file at once. You should use a code like the following (untested):
std::vectorstd::string paths = {“00001.dcm”, “00002.dcm”};
for (const auto& path : paths) {
std::string dicom;
Orthanc::SystemToolbox::ReadFile(dicom, path);
Json::Value upload;
OrthancPlugins::RestApiPost(upload, “/instances”, dicom, false);
}
If you absolutely want to upload multiple DICOM instances in one single call, and if you don’t want to create a ZIP file, you could use a STOW-RS call through the DICOMweb plugin:
https://book.orthanc-server.com/plugins/dicomweb.html
https://hg.orthanc-server.com/orthanc-dicomweb/file/default/Resources/Samples/Python/SendStow.py
HTH,
Sébastien-
Thanks Sebastien,
I notice that if I am using PostMan (or curl) to send multiple dicom files (form data) to the http route: localhost:8042/instances, then orthanc can handle them properly. However if I am using c++ sdk then the OrthancPlugins::RestApiPost does not have signature to send the form-data. What I want to achieve is to digest multiple files at once instead of sending one by one.
Indeed, the “/instances” URI also accepts “multipart/form-data” requests, but this is normally only meant to be used by HTML/JavaScript applications or HTTP clients (such as postman or curl). Plugins or REST clients should favor DICOMweb STOW-RS and ZIP uploads (cf. my previous message).
That being said, if you absolutely want to use “/instances” with “multipart/form-data”, check out RFC1867 that contains samples about how to properly format the headers and the body of a suitable POST request:
https://www.rfc-editor.org/rfc/rfc1867
You should then be able to use “OrthancPlugins::RestApiPost()”.
HTH,
Sébastien-
Great, thank you for your lots of useful information.