diff OrthancServer/OrthancRestApi.cpp @ 699:2929e17f8447

add attachments to resources
author Sebastien Jodogne <s.jodogne@gmail.com>
date Wed, 05 Feb 2014 17:49:30 +0100
parents aae83e1e31f7
children f9052558eada
line wrap: on
line diff
--- a/OrthancServer/OrthancRestApi.cpp	Wed Feb 05 17:20:43 2014 +0100
+++ b/OrthancServer/OrthancRestApi.cpp	Wed Feb 05 17:49:30 2014 +0100
@@ -2018,6 +2018,23 @@
   }
 
 
+  static void UploadAttachment(RestApi::PostCall& call)
+  {
+    RETRIEVE_CONTEXT(call);
+    CheckValidResourceType(call);
+ 
+    std::string publicId = call.GetUriComponent("id", "");
+    std::string name = call.GetUriComponent("name", "");
+
+    const void* data = call.GetPostBody().size() ? &call.GetPostBody()[0] : NULL;
+
+    if (context.AddAttachment(publicId, StringToContentType(name), data, call.GetPostBody().size()))
+    {
+      call.GetOutput().AnswerBuffer("{}", "application/json");
+    }
+  }
+
+
 
   // Registration of the various REST handlers --------------------------------
 
@@ -2073,6 +2090,7 @@
     Register("/{resourceType}/{id}/attachments/{name}/md5", GetAttachmentMD5);
     Register("/{resourceType}/{id}/attachments/{name}/size", GetAttachmentSize);
     Register("/{resourceType}/{id}/attachments/{name}/verify-md5", VerifyAttachment);
+    Register("/{resourceType}/{id}/attachments/{name}", UploadAttachment);
 
     Register("/patients/{id}/protected", IsProtectedPatient);
     Register("/patients/{id}/protected", SetPatientProtection);