changeset 701:f9052558eada

fix attachment
author Sebastien Jodogne <s.jodogne@gmail.com>
date Mon, 10 Feb 2014 14:30:56 +0100
parents 0fe6632864b9
children 7592a48e97e4
files OrthancServer/DatabaseWrapper.cpp OrthancServer/OrthancRestApi.cpp OrthancServer/ServerIndex.cpp
diffstat 3 files changed, 21 insertions(+), 22 deletions(-) [+]
line wrap: on
line diff
--- a/OrthancServer/DatabaseWrapper.cpp	Fri Feb 07 21:34:09 2014 +0100
+++ b/OrthancServer/DatabaseWrapper.cpp	Mon Feb 10 14:30:56 2014 +0100
@@ -463,7 +463,7 @@
   void DatabaseWrapper::DeleteAttachment(int64_t id,
                                          FileContentType attachment)
   {
-    SQLite::Statement s(db_, SQLITE_FROM_HERE, "DELETE FROM Resources WHERE internalId=?");
+    SQLite::Statement s(db_, SQLITE_FROM_HERE, "DELETE FROM AttachedFiles WHERE id=? AND fileType=?");
     s.BindInt64(0, id);
     s.BindInt(1, attachment);
     s.Run();
--- a/OrthancServer/OrthancRestApi.cpp	Fri Feb 07 21:34:09 2014 +0100
+++ b/OrthancServer/OrthancRestApi.cpp	Mon Feb 10 14:30:56 2014 +0100
@@ -2018,7 +2018,7 @@
   }
 
 
-  static void UploadAttachment(RestApi::PostCall& call)
+  static void UploadAttachment(RestApi::PutCall& call)
   {
     RETRIEVE_CONTEXT(call);
     CheckValidResourceType(call);
@@ -2026,9 +2026,9 @@
     std::string publicId = call.GetUriComponent("id", "");
     std::string name = call.GetUriComponent("name", "");
 
-    const void* data = call.GetPostBody().size() ? &call.GetPostBody()[0] : NULL;
+    const void* data = call.GetPutBody().size() ? &call.GetPutBody()[0] : NULL;
 
-    if (context.AddAttachment(publicId, StringToContentType(name), data, call.GetPostBody().size()))
+    if (context.AddAttachment(publicId, StringToContentType(name), data, call.GetPutBody().size()))
     {
       call.GetOutput().AnswerBuffer("{}", "application/json");
     }
@@ -2076,22 +2076,6 @@
     Register("/studies/{id}/statistics", GetResourceStatistics);
     Register("/series/{id}/statistics", GetResourceStatistics);
 
-    Register("/{resourceType}/{id}/metadata", ListMetadata);
-    Register("/{resourceType}/{id}/metadata/{name}", DeleteMetadata);
-    Register("/{resourceType}/{id}/metadata/{name}", GetMetadata);
-    Register("/{resourceType}/{id}/metadata/{name}", SetMetadata);
-
-    Register("/{resourceType}/{id}/attachments", ListAttachments);
-    Register("/{resourceType}/{id}/attachments/{name}", GetAttachmentOperations);
-    Register("/{resourceType}/{id}/attachments/{name}/compressed-data", GetAttachmentData<0>);
-    Register("/{resourceType}/{id}/attachments/{name}/compressed-md5", GetAttachmentCompressedMD5);
-    Register("/{resourceType}/{id}/attachments/{name}/compressed-size", GetAttachmentCompressedSize);
-    Register("/{resourceType}/{id}/attachments/{name}/data", GetAttachmentData<1>);
-    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);
     Register("/instances/{id}/file", GetInstanceFile);
@@ -2136,5 +2120,21 @@
     Register("/tools/generate-uid", GenerateUid);
     Register("/tools/execute-script", ExecuteScript);
     Register("/tools/now", GetNowIsoString);
+
+    Register("/{resourceType}/{id}/metadata", ListMetadata);
+    Register("/{resourceType}/{id}/metadata/{name}", DeleteMetadata);
+    Register("/{resourceType}/{id}/metadata/{name}", GetMetadata);
+    Register("/{resourceType}/{id}/metadata/{name}", SetMetadata);
+
+    Register("/{resourceType}/{id}/attachments", ListAttachments);
+    Register("/{resourceType}/{id}/attachments/{name}", GetAttachmentOperations);
+    Register("/{resourceType}/{id}/attachments/{name}/compressed-data", GetAttachmentData<0>);
+    Register("/{resourceType}/{id}/attachments/{name}/compressed-md5", GetAttachmentCompressedMD5);
+    Register("/{resourceType}/{id}/attachments/{name}/compressed-size", GetAttachmentCompressedSize);
+    Register("/{resourceType}/{id}/attachments/{name}/data", GetAttachmentData<1>);
+    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);
   }
 }
--- a/OrthancServer/ServerIndex.cpp	Fri Feb 07 21:34:09 2014 +0100
+++ b/OrthancServer/ServerIndex.cpp	Mon Feb 10 14:30:56 2014 +0100
@@ -819,8 +819,7 @@
 
     int64_t id;
     ResourceType type;
-    if (!db_->LookupResource(instanceUuid, id, type) ||
-        type != ResourceType_Instance)
+    if (!db_->LookupResource(instanceUuid, id, type))
     {
       throw OrthancException(ErrorCode_InternalError);
     }