18#include <drogon/exports.h>
20#include <unordered_map>
34class DROGON_EXPORT HttpFile
37 explicit HttpFile(std::shared_ptr<HttpFileImpl> &&implPtr)
noexcept;
57 void setFile(const
char *data,
size_t length) noexcept;
73 int save(const
std::
string &path) const noexcept;
81 int saveAs(const
std::
string &fileName) const noexcept;
117 std::shared_ptr<HttpFileImpl> implPtr_;
122class DROGON_EXPORT MultiPartParser
126 MultiPartParser(
const MultiPartParser &other) =
default;
127 MultiPartParser(MultiPartParser &&other) =
default;
128 ~MultiPartParser(){};
142 template <
typename T>
146 auto it = params.find(key);
147 if (it != params.end())
151 return std::optional<T>(utils::fromString<T>(it->second));
153 catch (
const std::exception &e)
155 LOG_ERROR << e.what();
156 return std::optional<T>{};
161 return std::optional<T>{};
168 template <
typename T>
175 int parse(
const HttpRequestPtr &req);
178 std::vector<HttpFile> files_;
179 SafeStringMap<std::string> parameters_;
180 int parse(
const HttpRequestPtr &req,
181 const char *boundaryData,
183 int parseEntity(
const HttpRequestPtr &req,
const std::string & getFileName() const noexcept
Return the file name;.
const char * fileData() const noexcept
return the pointer of the file data.
std::string_view fileContent() const noexcept
return the content of the file.
Definition MultiPart.h:88
const std::string & getItemName() const noexcept
Return the name of the item in multiple parts.
int save() const noexcept
Save the file to the file system.
void setFile(const char *data, size_t length) noexcept
FileType getFileType() const noexcept
Return the type of file.
size_t fileLength() const noexcept
Return the file length.
void setFileName(const std::string &fileName) noexcept
Set the file name, usually called by the MultiPartParser parser.
drogon::ContentType getContentType() const noexcept
Return the content-type of the file.
int saveAs(const std::string &fileName) const noexcept
Save the file to file system with a new name.
std::string_view getFileExtension() const noexcept
const std::string & getContentTransferEncoding() const noexcept
Return the content transfer encoding of the file.
std::string getMd5() const noexcept
Return the md5 string of the file.
Definition MultiPart.h:123
T getParameter(const std::string &key)
Definition MultiPart.h:169
const std::vector< HttpFile > & getFiles() const
int parse(const HttpRequestPtr &req)
Parse the http request stream to get files and parameters.
const SafeStringMap< std::string > & getParameters() const
std::optional< T > getOptionalParameter(const std::string &key)
Definition MultiPart.h:143
std::unordered_map< std::string, HttpFile > getFilesMap() const
Get files in a map, the keys of the map are item names of the files.
Drogon Test is a minimal effort test framework developed because the major C++ test frameworks doesn'...
Definition Attribute.h:23
MultiPartParser FileUpload
In order to be compatible with old interfaces.
Definition MultiPart.h:189