drogon
C++14/17-based HTTP application framework
Loading...
Searching...
No Matches
UploadFile.h
1
14
15#pragma once
16#include <string>
17
18namespace drogon
19{
25{
26 public:
28
35 explicit UploadFile(const std::string &filePath,
36 const std::string &fileName = "",
37 const std::string &itemName = "file",
38 ContentType contentType = CT_NONE)
39 : path_(filePath), itemName_(itemName), contentType_(contentType)
40 {
41 if (!fileName.empty())
42 {
43 fileName_ = fileName;
44 }
45 else
46 {
47 auto pos = filePath.rfind('/');
48 if (pos != std::string::npos)
49 {
50 fileName_ = filePath.substr(pos + 1);
51 }
52 else
53 {
54 fileName_ = filePath;
55 }
56 }
57 }
58
60
67 explicit UploadFile(const void *data,
68 const size_t len,
69 const std::string &fileName = "memory.bin",
70 const std::string &itemName = "file",
71 ContentType contentType = CT_APPLICATION_OCTET_STREAM)
72 : data_(data),
73 len_(len),
74 fileName_(fileName),
75 itemName_(itemName),
76 contentType_(contentType)
77 {
78 }
79
80 const std::string &path() const
81 {
82 return path_;
83 }
84
85 const std::string &fileName() const
86 {
87 return fileName_;
88 }
89
90 const std::string &itemName() const
91 {
92 return itemName_;
93 }
94
95 ContentType contentType() const
96 {
97 return contentType_;
98 }
99
100 const void *data() const
101 {
102 return data_;
103 }
104
105 size_t dataLength() const
106 {
107 return len_;
108 }
109
110 private:
111 const void *data_ = nullptr;
112 size_t len_ = 0;
113 std::string path_;
114 std::string fileName_;
115 std::string itemName_;
116 ContentType contentType_;
117};
118} // namespace drogon
UploadFile(const void *data, const size_t len, const std::string &fileName="memory.bin", const std::string &itemName="file", ContentType contentType=CT_APPLICATION_OCTET_STREAM)
Constructor.
Definition UploadFile.h:67
UploadFile(const std::string &filePath, const std::string &fileName="", const std::string &itemName="file", ContentType contentType=CT_NONE)
Constructor.
Definition UploadFile.h:35
Drogon Test is a minimal effort test framework developed because the major C++ test frameworks doesn'...
Definition Attribute.h:23