diff OrthancServer/ServerContext.cpp @ 699:2929e17f8447

add attachments to resources
author Sebastien Jodogne <s.jodogne@gmail.com>
date Wed, 05 Feb 2014 17:49:30 +0100
parents dd1ce9a2844c
children 309e686b41e7
line wrap: on
line diff
--- a/OrthancServer/ServerContext.cpp	Wed Feb 05 17:20:43 2014 +0100
+++ b/OrthancServer/ServerContext.cpp	Wed Feb 05 17:49:30 2014 +0100
@@ -284,4 +284,34 @@
     accessor_.SetStoreMD5(storeMD5);
   }
 
+
+  bool ServerContext::AddAttachment(const std::string& resourceId,
+                                    FileContentType attachmentType,
+                                    const void* data,
+                                    size_t size)
+  {
+    LOG(INFO) << "Adding attachment " << EnumerationToString(attachmentType) << " to resource " << resourceId;
+    
+    if (compressionEnabled_)
+    {
+      accessor_.SetCompressionForNextOperations(CompressionType_Zlib);
+    }
+    else
+    {
+      accessor_.SetCompressionForNextOperations(CompressionType_None);
+    }      
+
+    FileInfo info = accessor_.Write(data, size, attachmentType);
+    StoreStatus status = index_.AddAttachment(info, resourceId);
+
+    if (status != StoreStatus_Success)
+    {
+      storage_.Remove(info.GetUuid());
+      return false;
+    }
+    else
+    {
+      return true;
+    }
+  }
 }