Browse Source

Updated example/upload.cc

yhirose 6 years ago
parent
commit
b4f808da74
1 changed files with 18 additions and 7 deletions
  1. 18 7
      example/upload.cc

+ 18 - 7
example/upload.cc

@@ -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");
-    cout << "file length: " << file.content.length() << ":" << file.filename
-         << endl;
-
-    ofstream ofs(file.filename, ios::binary);
-    ofs << file.content;
+    auto image_file = req.get_file_value("image_file");
+    auto text_file = req.get_file_value("text_file");
+
+    cout << "image file length: " << image_file.content.length() << endl
+         << "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");
   });
   });