Mercurial > hg > orthanc
changeset 4358:d6929f052ec4
ZIP archives containing DICOM files can be uploaded using WebDAV
author | Sebastien Jodogne <s.jodogne@gmail.com> |
---|---|
date | Tue, 08 Dec 2020 15:22:28 +0100 |
parents | 886bc367aeb2 |
children | 074f37013186 |
files | NEWS OrthancServer/Sources/OrthancWebDav.cpp |
diffstat | 2 files changed, 55 insertions(+), 13 deletions(-) [+] |
line wrap: on
line diff
--- 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 --------
--- 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<ZipReader> 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);