mirror of
https://github.com/yhirose/cpp-httplib
synced 2024-11-21 06:26:02 -07:00
Updated example/upload.cc
This commit is contained in:
parent
7fbb8bb3fd
commit
b4f808da74
1 changed files with 17 additions and 6 deletions
|
@ -13,7 +13,8 @@ using namespace std;
|
||||||
|
|
||||||
const char *html = R"(
|
const char *html = R"(
|
||||||
<form id="formElem">
|
<form id="formElem">
|
||||||
<input type="file" name="file" accept="image/*">
|
<input type="file" name="image_file" accept="image/*">
|
||||||
|
<input type="file" name="text_file" accept="text/*">
|
||||||
<input type="submit">
|
<input type="submit">
|
||||||
</form>
|
</form>
|
||||||
<script>
|
<script>
|
||||||
|
@ -36,12 +37,22 @@ int main(void) {
|
||||||
});
|
});
|
||||||
|
|
||||||
svr.Post("/post", [](const Request &req, Response &res) {
|
svr.Post("/post", [](const Request &req, Response &res) {
|
||||||
auto file = req.get_file_value("file");
|
auto image_file = req.get_file_value("image_file");
|
||||||
cout << "file length: " << file.content.length() << ":" << file.filename
|
auto text_file = req.get_file_value("text_file");
|
||||||
<< endl;
|
|
||||||
|
|
||||||
ofstream ofs(file.filename, ios::binary);
|
cout << "image file length: " << image_file.content.length() << endl
|
||||||
ofs << file.content;
|
<< "image file name: " << image_file.filename << endl
|
||||||
|
<< "text file length: " << text_file.content.length() << endl
|
||||||
|
<< "text file name: " << text_file.filename << endl;
|
||||||
|
|
||||||
|
{
|
||||||
|
ofstream ofs(image_file.filename, ios::binary);
|
||||||
|
ofs << image_file.content;
|
||||||
|
}
|
||||||
|
{
|
||||||
|
ofstream ofs(text_file.filename);
|
||||||
|
ofs << text_file.content;
|
||||||
|
}
|
||||||
|
|
||||||
res.set_content("done", "text/plain");
|
res.set_content("done", "text/plain");
|
||||||
});
|
});
|
||||||
|
|
Loading…
Reference in a new issue