# HG changeset patch # User Sebastien Jodogne # Date 1607437348 -3600 # Node ID d6929f052ec4eb6d806be35ef60b8dac311e3c47 # Parent 886bc367aeb29599ed64ed0bf1142c599357c5b5 ZIP archives containing DICOM files can be uploaded using WebDAV diff -r 886bc367aeb2 -r d6929f052ec4 NEWS --- a/NEWS Tue Dec 08 13:17:40 2020 +0100 +++ b/NEWS Tue Dec 08 15:22:28 2020 +0100 @@ -1,6 +1,10 @@ Pending changes in the mainline =============================== +General +------- + +* ZIP archives containing DICOM files can be uploaded using WebDAV REST API -------- diff -r 886bc367aeb2 -r d6929f052ec4 OrthancServer/Sources/OrthancWebDav.cpp --- a/OrthancServer/Sources/OrthancWebDav.cpp Tue Dec 08 13:17:40 2020 +0100 +++ b/OrthancServer/Sources/OrthancWebDav.cpp Tue Dec 08 15:22:28 2020 +0100 @@ -33,6 +33,7 @@ #include "OrthancWebDav.h" +#include "../../OrthancFramework/Sources/Compression/ZipReader.h" #include "../../OrthancFramework/Sources/DicomFormat/DicomArray.h" #include "../../OrthancFramework/Sources/DicomParsing/FromDcmtkBridge.h" #include "../../OrthancFramework/Sources/HttpServer/WebDavStorage.h" @@ -1266,26 +1267,63 @@ boost::posix_time::ptime time; if (uploads_.GetFileContent(mime, content, time, uri)) { - DicomInstanceToStore instance; - instance.SetOrigin(DicomInstanceOrigin::FromWebDav()); - instance.SetBuffer(content.c_str(), content.size()); - bool success = false; - try + if (ZipReader::IsZipMemoryBuffer(content)) { - std::string publicId; - StoreStatus status = context_.Store(publicId, instance, StoreInstanceMode_Default); - if (status == StoreStatus_Success || - status == StoreStatus_AlreadyStored) + // New in Orthanc 1.9.0 + std::unique_ptr reader(ZipReader::CreateFromMemory(content)); + + std::string filename, content; + while (reader->ReadNextFile(filename, content)) { - LOG(INFO) << "Successfully imported DICOM instance from WebDAV: " - << path << " (Orthanc ID: " << publicId << ")"; - success = true; + if (!content.empty()) + { + LOG(INFO) << "Uploading DICOM file extracted from a ZIP archive in WebDAV: " << filename; + + DicomInstanceToStore instance; + instance.SetOrigin(DicomInstanceOrigin::FromWebDav()); + instance.SetBuffer(content.c_str(), content.size()); + + std::string publicId; + + try + { + context_.Store(publicId, instance, StoreInstanceMode_Default); + } + catch (OrthancException& e) + { + if (e.GetErrorCode() == ErrorCode_BadFileFormat) + { + LOG(ERROR) << "Cannot import non-DICOM file from ZIP archive: " << filename; + } + } + } } + + success = true; } - catch (OrthancException& e) + else { + DicomInstanceToStore instance; + instance.SetOrigin(DicomInstanceOrigin::FromWebDav()); + instance.SetBuffer(content.c_str(), content.size()); + + try + { + std::string publicId; + StoreStatus status = context_.Store(publicId, instance, StoreInstanceMode_Default); + if (status == StoreStatus_Success || + status == StoreStatus_AlreadyStored) + { + LOG(INFO) << "Successfully imported DICOM instance from WebDAV: " + << path << " (Orthanc ID: " << publicId << ")"; + success = true; + } + } + catch (OrthancException& e) + { + } } uploads_.DeleteItem(uri);