comparison 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
comparison
equal deleted inserted replaced
698:aae83e1e31f7 699:2929e17f8447
2016 LOG(INFO) << "The attachment " << name << " of resource " << publicId << " has bad MD5!"; 2016 LOG(INFO) << "The attachment " << name << " of resource " << publicId << " has bad MD5!";
2017 } 2017 }
2018 } 2018 }
2019 2019
2020 2020
2021 static void UploadAttachment(RestApi::PostCall& call)
2022 {
2023 RETRIEVE_CONTEXT(call);
2024 CheckValidResourceType(call);
2025
2026 std::string publicId = call.GetUriComponent("id", "");
2027 std::string name = call.GetUriComponent("name", "");
2028
2029 const void* data = call.GetPostBody().size() ? &call.GetPostBody()[0] : NULL;
2030
2031 if (context.AddAttachment(publicId, StringToContentType(name), data, call.GetPostBody().size()))
2032 {
2033 call.GetOutput().AnswerBuffer("{}", "application/json");
2034 }
2035 }
2036
2037
2021 2038
2022 // Registration of the various REST handlers -------------------------------- 2039 // Registration of the various REST handlers --------------------------------
2023 2040
2024 OrthancRestApi::OrthancRestApi(ServerContext& context) : 2041 OrthancRestApi::OrthancRestApi(ServerContext& context) :
2025 context_(context) 2042 context_(context)
2071 Register("/{resourceType}/{id}/attachments/{name}/compressed-size", GetAttachmentCompressedSize); 2088 Register("/{resourceType}/{id}/attachments/{name}/compressed-size", GetAttachmentCompressedSize);
2072 Register("/{resourceType}/{id}/attachments/{name}/data", GetAttachmentData<1>); 2089 Register("/{resourceType}/{id}/attachments/{name}/data", GetAttachmentData<1>);
2073 Register("/{resourceType}/{id}/attachments/{name}/md5", GetAttachmentMD5); 2090 Register("/{resourceType}/{id}/attachments/{name}/md5", GetAttachmentMD5);
2074 Register("/{resourceType}/{id}/attachments/{name}/size", GetAttachmentSize); 2091 Register("/{resourceType}/{id}/attachments/{name}/size", GetAttachmentSize);
2075 Register("/{resourceType}/{id}/attachments/{name}/verify-md5", VerifyAttachment); 2092 Register("/{resourceType}/{id}/attachments/{name}/verify-md5", VerifyAttachment);
2093 Register("/{resourceType}/{id}/attachments/{name}", UploadAttachment);
2076 2094
2077 Register("/patients/{id}/protected", IsProtectedPatient); 2095 Register("/patients/{id}/protected", IsProtectedPatient);
2078 Register("/patients/{id}/protected", SetPatientProtection); 2096 Register("/patients/{id}/protected", SetPatientProtection);
2079 Register("/instances/{id}/file", GetInstanceFile); 2097 Register("/instances/{id}/file", GetInstanceFile);
2080 Register("/instances/{id}/export", ExportInstanceFile); 2098 Register("/instances/{id}/export", ExportInstanceFile);