From df82728a452ce9dab568d975991e9a0afb41a98f Mon Sep 17 00:00:00 2001 From: An Tao Date: Tue, 8 Oct 2019 15:46:48 +0800 Subject: [PATCH] Add interfaces for accessing content of attachments. (#274) --- lib/inc/drogon/MultiPart.h | 26 +++++++++++++++++++++++--- lib/src/MultiPart.cc | 2 +- 2 files changed, 24 insertions(+), 4 deletions(-) diff --git a/lib/inc/drogon/MultiPart.h b/lib/inc/drogon/MultiPart.h index 093e4ea0..406f28f6 100644 --- a/lib/inc/drogon/MultiPart.h +++ b/lib/inc/drogon/MultiPart.h @@ -70,13 +70,33 @@ class HttpFile int saveAs(const std::string &filename) const; /// Return the file length. - int64_t fileLength() const + int64_t fileLength() const noexcept { return _fileContent.length(); }; - + /// Return the file content. + char *fileData() noexcept + { +#if __cplusplus >= 201703L + return _fileContent.data(); +#else + return (char *)(_fileContent.data()); +#endif + } + const char *fileData() const noexcept + { + return _fileContent.data(); + } + std::string &fileContent() noexcept + { + return _fileContent; + } + const std::string &fileContent() const noexcept + { + return _fileContent; + } /// Return the md5 string of the file - const std::string getMd5() const; + std::string getMd5() const; protected: int saveTo(const std::string &pathAndFilename) const; diff --git a/lib/src/MultiPart.cc b/lib/src/MultiPart.cc index d92f6ccb..1094c6c2 100644 --- a/lib/src/MultiPart.cc +++ b/lib/src/MultiPart.cc @@ -222,7 +222,7 @@ int HttpFile::saveTo(const std::string &pathAndFilename) const return -1; } } -const std::string HttpFile::getMd5() const +std::string HttpFile::getMd5() const { #ifdef OpenSSL_FOUND MD5_CTX c;