# HG changeset patch # User Sebastien Jodogne # Date 1410437088 -7200 # Node ID 200fcac0deb4e2b6476b9de03c18dfb287fe65da # Parent 0479d02c677815cd851b4555ca60501672c5b8af optimization for access to attachments diff -r 0479d02c6778 -r 200fcac0deb4 Core/Enumerations.cpp --- a/Core/Enumerations.cpp Thu Sep 11 13:06:16 2014 +0200 +++ b/Core/Enumerations.cpp Thu Sep 11 14:04:48 2014 +0200 @@ -549,4 +549,20 @@ // The encoding was properly detected return true; } + + + const char* GetMimeType(FileContentType type) + { + switch (type) + { + case FileContentType_Dicom: + return "application/dicom"; + + case FileContentType_DicomAsJson: + return "application/json"; + + default: + return "application/octet-stream"; + } + } } diff -r 0479d02c6778 -r 200fcac0deb4 Core/Enumerations.h --- a/Core/Enumerations.h Thu Sep 11 13:06:16 2014 +0200 +++ b/Core/Enumerations.h Thu Sep 11 14:04:48 2014 +0200 @@ -308,4 +308,6 @@ bool GetDicomEncoding(Encoding& encoding, const char* specificCharacterSet); + + const char* GetMimeType(FileContentType type); } diff -r 0479d02c6778 -r 200fcac0deb4 OrthancServer/OrthancRestApi/OrthancRestResources.cpp --- a/OrthancServer/OrthancRestApi/OrthancRestResources.cpp Thu Sep 11 13:06:16 2014 +0200 +++ b/OrthancServer/OrthancRestApi/OrthancRestResources.cpp Thu Sep 11 14:04:48 2014 +0200 @@ -112,7 +112,7 @@ ServerContext& context = OrthancRestApi::GetContext(call); std::string publicId = call.GetUriComponent("id", ""); - context.AnswerDicomFile(call.GetOutput(), publicId, FileContentType_Dicom); + context.AnswerAttachment(call.GetOutput(), publicId, FileContentType_Dicom); } @@ -138,18 +138,18 @@ std::string publicId = call.GetUriComponent("id", ""); - Json::Value full; - context.ReadJson(full, publicId); - if (simplify) { + Json::Value full; + context.ReadJson(full, publicId); + Json::Value simplified; SimplifyTags(simplified, full); call.GetOutput().AnswerJson(simplified); } else { - call.GetOutput().AnswerJson(full); + context.AnswerAttachment(call.GetOutput(), publicId, FileContentType_DicomAsJson); } } @@ -449,13 +449,19 @@ CheckValidResourceType(call); std::string publicId = call.GetUriComponent("id", ""); - std::string name = call.GetUriComponent("name", ""); + FileContentType type = StringToContentType(call.GetUriComponent("name", "")); - std::string content; - context.ReadFile(content, publicId, StringToContentType(name), - (uncompress == 1)); - - call.GetOutput().AnswerBuffer(content, "application/octet-stream"); + if (uncompress) + { + context.AnswerAttachment(call.GetOutput(), publicId, type); + } + else + { + // Return the raw data (possibly compressed), as stored on the filesystem + std::string content; + context.ReadFile(content, publicId, type, false); + call.GetOutput().AnswerBuffer(content, "application/octet-stream"); + } } diff -r 0479d02c6778 -r 200fcac0deb4 OrthancServer/ServerContext.cpp --- a/OrthancServer/ServerContext.cpp Thu Sep 11 13:06:16 2014 +0200 +++ b/OrthancServer/ServerContext.cpp Thu Sep 11 14:04:48 2014 +0200 @@ -391,9 +391,9 @@ - void ServerContext::AnswerDicomFile(RestApiOutput& output, - const std::string& instancePublicId, - FileContentType content) + void ServerContext::AnswerAttachment(RestApiOutput& output, + const std::string& instancePublicId, + FileContentType content) { FileInfo attachment; if (!index_.LookupAttachment(attachment, instancePublicId, content)) @@ -404,7 +404,7 @@ accessor_.SetCompressionForNextOperations(attachment.GetCompressionType()); std::auto_ptr sender(accessor_.ConstructHttpFileSender(attachment.GetUuid(), attachment.GetContentType())); - sender->SetContentType("application/dicom"); + sender->SetContentType(GetMimeType(content)); sender->SetDownloadFilename(instancePublicId + ".dcm"); output.AnswerFile(*sender); } diff -r 0479d02c6778 -r 200fcac0deb4 OrthancServer/ServerContext.h --- a/OrthancServer/ServerContext.h Thu Sep 11 13:06:16 2014 +0200 +++ b/OrthancServer/ServerContext.h Thu Sep 11 14:04:48 2014 +0200 @@ -164,9 +164,9 @@ StoreStatus Store(std::string& resultPublicId, DicomInstanceToStore& dicom); - void AnswerDicomFile(RestApiOutput& output, - const std::string& instancePublicId, - FileContentType content); + void AnswerAttachment(RestApiOutput& output, + const std::string& instancePublicId, + FileContentType content); void ReadJson(Json::Value& result, const std::string& instancePublicId);