{"id":5378,"date":"2026-04-15T15:17:44","date_gmt":"2026-04-15T06:17:44","guid":{"rendered":"https:\/\/www.freelifemakers.org\/wordpress\/?p=5378"},"modified":"2026-04-15T15:22:39","modified_gmt":"2026-04-15T06:22:39","slug":"webserver-httplib-large-file-upload","status":"publish","type":"post","link":"https:\/\/www.freelifemakers.org\/wordpress\/index.php\/2026\/04\/15\/webserver-httplib-large-file-upload\/","title":{"rendered":"[Webserver]httplib webserver+large file upload\u00a0"},"content":{"rendered":"\n<p>\ud83d\udc49\ud83c\udffb  \ub300\uc6a9\ub7c9 \ud30c\uc77c \uc5c5\ub85c\ub4dc\ub97c \uc704\ud55c \uc124\uba85\uc785\ub2c8\ub2e4.<br>This is an explanation for uploading large files.<\/p>\n\n\n\n<p>\ud83d\udc49\ud83c\udffb \uc5c5\ub85c\ub4dc \uc9c4\ud589\ub960\uc744 \ud655\uc778\uc744 \ud560 \uc218 \uc788\uc2b5\ub2c8\ub2e4.<br>You can check the upload progress.<\/p>\n\n\n\n<p>\ud83d\udc49\ud83c\udffb \ud14c\uc2a4\ud2b8\ub294 macOS\uc5d0\uc11c http\ub85c \ud14c\uc2a4\ud2b8 \ud588\uc2b5\ub2c8\ub2e4.<br>The test was performed on macOS using http.<\/p>\n\n\n\n<p>\ud83d\udc49\ud83c\udffb macOS\uc5d0\uc11c \ud14c\uc2a4\ud2b8 \ud588\uc9c0\ub9cc \ub9ac\ub205\uc2a4\uc5d0\uc11c \uc0ac\uc6a9\ud574\ub3c4 \ub429\ub2c8\ub2e4.<br>I tested it on macOS, but it can also be used on Linux.<\/p>\n\n\n\n<p>\ud83d\udc49\ud83c\udffb \ub9ac\ub205\uc2a4\uc5d0\uc11c \uc0ac\uc6a9\uc2dc \ubc29\ud654\ubcbd\uc5d0\uc11c 5080\ud3ec\ud2b8 \uc624\ud508\ub418\uc5b4\uc57c \ud569\ub2c8\ub2e4.(\uc774\uc804 \uac8c\uc2dc\ubb3c\uc744 \ucc38\uc870 \ud558\uc138\uc694)<br>When using on Linux, port 5080 must be open in the firewall. (Please refer to the previous post.)<\/p>\n\n\n\n<p>\u2714\ufe0f \ucf54\ub4dc \/ Code<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>\/\/#define CPPHTTPLIB_OPENSSL_SUPPORT \/\/ HTTPS\n#include \"httplib.h\"\n#include &lt;filesystem&gt;\n#include &lt;fstream&gt;\n#include &lt;iostream&gt;\n\nint main() {\n    \/\/ HTTP\uba74 Server, HTTPS\uba74 SSLServer \uc0ac\uc6a9\n    \/\/ Use Server for HTTP, SSLServer for HTTPS\n\n    httplib::Server svr;\n\n    \/\/ httplib::SSLServer svr(\".\/fullchain.pem\", \".\/privkey.pem\"); \/\/ HTTPS\n\n    std::filesystem::create_directories(\".\/uploads\");\n    svr.set_payload_max_length(1024ULL * 1024 * 1024 * 10); \/\/ 10GB\n\n    \/\/ Multipart \uc5c5\ub85c\ub4dc \/ Multipart Upload\n    svr.Post(\"\/upload\/multipart\", &#91;&amp;](const httplib::Request&amp; req, httplib::Response&amp; res,\n                                      const httplib::ContentReader&amp; reader) {\n        if (!req.is_multipart_form_data()) {\n            res.status = 400;\n            res.set_content(\"not multipart\", \"text\/plain\");\n            return;\n        }\n\n        std::ofstream ofs;\n        bool ok = reader(\n            &#91;&amp;](const httplib::FormData&amp; part) {\n                if (part.name == \"file\") {\n                    std::string name = httplib::sanitize_filename(part.filename.empty() ? \"upload.bin\" : part.filename);\n                    ofs.open(\".\/uploads\/\" + name, std::ios::binary);\n                    if (!ofs) return false;\n                }\n                return true;\n            },\n            &#91;&amp;](const char* data, size_t len) {\n                if (ofs) ofs.write(data, static_cast&lt;std::streamsize&gt;(len));\n                return true;\n            });\n\n        if (ofs) ofs.close();\n\n        if (!ok) {\n            res.status = 500;\n            res.set_content(\"multipart stream failed\", \"text\/plain\");\n            return;\n        }\n\n        res.set_content(\"multipart upload ok\", \"text\/plain\");\n    });\n\n    \/\/ \uc5c5\ub85c\ub4dc \uc9c4\ud589\ub960 \ud45c\uc2dc\n    \/\/ HTML form displaying upload status\n    svr.Get(\"\/\", &#91;](const httplib::Request&amp;, httplib::Response&amp; res) {\n        res.set_content(R\"(\n    &lt;!doctype html&gt;\n    &lt;html&gt;\n    &lt;body&gt;\n      &lt;h1&gt;Upload&lt;\/h1&gt;\n\n      &lt;form id=\"uploadForm\"&gt;\n        &lt;input type=\"file\" id=\"file\" name=\"file\" required \/&gt;\n        &lt;button type=\"submit\"&gt;Upload&lt;\/button&gt;\n      &lt;\/form&gt;\n\n      &lt;p id=\"percent\"&gt;0%&lt;\/p&gt;\n      &lt;progress id=\"bar\" value=\"0\" max=\"100\" style=\"width: 300px;\"&gt;&lt;\/progress&gt;\n      &lt;pre id=\"result\"&gt;&lt;\/pre&gt;\n\n      &lt;script&gt;\n        const form = document.getElementById('uploadForm');\n        const bar = document.getElementById('bar');\n        const percent = document.getElementById('percent');\n        const result = document.getElementById('result');\n\n        form.addEventListener('submit', (e) =&gt; {\n          e.preventDefault();\n\n          const fileInput = document.getElementById('file');\n          if (!fileInput.files.length) return;\n\n          const data = new FormData();\n          data.append('file', fileInput.files&#91;0]);\n\n          const xhr = new XMLHttpRequest();\n          xhr.open('POST', '\/upload\/multipart', true);\n\n          xhr.upload.onprogress = (evt) =&gt; {\n            if (evt.lengthComputable) {\n              const p = Math.round((evt.loaded \/ evt.total) * 100);\n              bar.value = p;\n              percent.textContent = p + '%';\n            }\n          };\n\n          xhr.onload = () =&gt; {\n            result.textContent = 'status: ' + xhr.status + '\\\\n' + xhr.responseText;\n          };\n\n          xhr.onerror = () =&gt; {\n            result.textContent = 'upload failed';\n          };\n\n          xhr.send(data);\n        });\n      &lt;\/script&gt;\n    &lt;\/body&gt;\n    &lt;\/html&gt;\n    )\", \"text\/html; charset=utf-8\");\n    });\n\n    std::cout &lt;&lt; \"listen: http:\/\/0.0.0.0:5080\\n\";\n    svr.listen(\"0.0.0.0\", 5080);\n}\n<\/code><\/pre>\n\n\n\n<p>\u2714\ufe0f \ucef4\ud30c\uc77c \/ Compiling<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>g++ large_upload_server.cpp -o large_upload_server -std=c++17 -pthread  <\/code><\/pre>\n\n\n\n<p>\u2714\ufe0f \uc11c\ubc84 \uc2e4\ud589 \/ Run Server<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>.\/large_upload_server<\/code><\/pre>\n\n\n\n<figure class=\"wp-block-image size-large\"><img loading=\"lazy\" decoding=\"async\" width=\"1024\" height=\"123\" src=\"https:\/\/www.freelifemakers.org\/wordpress\/wp-content\/uploads\/2026\/04\/server-jpg-1024x123.jpg\" alt=\"\" class=\"wp-image-5382\" srcset=\"https:\/\/www.freelifemakers.org\/wordpress\/wp-content\/uploads\/2026\/04\/server-jpg-1024x123.jpg 1024w, https:\/\/www.freelifemakers.org\/wordpress\/wp-content\/uploads\/2026\/04\/server-jpg-300x36.jpg 300w, https:\/\/www.freelifemakers.org\/wordpress\/wp-content\/uploads\/2026\/04\/server-jpg-768x93.jpg 768w, https:\/\/www.freelifemakers.org\/wordpress\/wp-content\/uploads\/2026\/04\/server-jpg-1536x185.jpg 1536w, https:\/\/www.freelifemakers.org\/wordpress\/wp-content\/uploads\/2026\/04\/server-jpg-400x48.jpg 400w, https:\/\/www.freelifemakers.org\/wordpress\/wp-content\/uploads\/2026\/04\/server-jpg-800x96.jpg 800w, https:\/\/www.freelifemakers.org\/wordpress\/wp-content\/uploads\/2026\/04\/server-jpg.jpg 1594w\" sizes=\"auto, (max-width: 1024px) 100vw, 1024px\" \/><figcaption class=\"wp-element-caption\">\uc11c\ubc84 \uc2e4\ud589 \/ Run Server<\/figcaption><\/figure>\n\n\n\n<p>\u2714\ufe0f \ube0c\ub77c\uc6b0\uc800 \uc811\uc18d \/ Browser Access<\/p>\n\n\n\n<p>&#8212; \ud30c\uc77c \uc5c5\ub85c\ub4dc \ud3fc \/ file upload form<\/p>\n\n\n\n<figure class=\"wp-block-image size-full\"><img loading=\"lazy\" decoding=\"async\" width=\"816\" height=\"774\" src=\"https:\/\/www.freelifemakers.org\/wordpress\/wp-content\/uploads\/2026\/04\/upload_form-jpg.jpg\" alt=\"\" class=\"wp-image-5385\" srcset=\"https:\/\/www.freelifemakers.org\/wordpress\/wp-content\/uploads\/2026\/04\/upload_form-jpg.jpg 816w, https:\/\/www.freelifemakers.org\/wordpress\/wp-content\/uploads\/2026\/04\/upload_form-jpg-300x285.jpg 300w, https:\/\/www.freelifemakers.org\/wordpress\/wp-content\/uploads\/2026\/04\/upload_form-jpg-768x728.jpg 768w, https:\/\/www.freelifemakers.org\/wordpress\/wp-content\/uploads\/2026\/04\/upload_form-jpg-400x379.jpg 400w, https:\/\/www.freelifemakers.org\/wordpress\/wp-content\/uploads\/2026\/04\/upload_form-jpg-800x759.jpg 800w\" sizes=\"auto, (max-width: 816px) 100vw, 816px\" \/><figcaption class=\"wp-element-caption\">\ud30c\uc77c \uc5c5\ub85c\ub4dc \ud3fc \/ file upload form<\/figcaption><\/figure>\n\n\n\n<p>&#8211;\ud30c\uc77c \uc5c5\ub85c\ub4dc \uc644\ub8cc \/ File upload complete<\/p>\n\n\n\n<figure class=\"wp-block-image size-full\"><img loading=\"lazy\" decoding=\"async\" width=\"794\" height=\"858\" src=\"https:\/\/www.freelifemakers.org\/wordpress\/wp-content\/uploads\/2026\/04\/upload_complete-jpg.jpg\" alt=\"\" class=\"wp-image-5387\" srcset=\"https:\/\/www.freelifemakers.org\/wordpress\/wp-content\/uploads\/2026\/04\/upload_complete-jpg.jpg 794w, https:\/\/www.freelifemakers.org\/wordpress\/wp-content\/uploads\/2026\/04\/upload_complete-jpg-278x300.jpg 278w, https:\/\/www.freelifemakers.org\/wordpress\/wp-content\/uploads\/2026\/04\/upload_complete-jpg-768x830.jpg 768w, https:\/\/www.freelifemakers.org\/wordpress\/wp-content\/uploads\/2026\/04\/upload_complete-jpg-400x432.jpg 400w\" sizes=\"auto, (max-width: 794px) 100vw, 794px\" \/><figcaption class=\"wp-element-caption\">\ud30c\uc77c \uc5c5\ub85c\ub4dc \uc644\ub8cc \/ File upload complete<\/figcaption><\/figure>\n\n\n\n<p>&#8212; \uc5c5\ub85c\ub4dc \uc0c1\ud0dc \ud655\uc778 \/ Check upload status<\/p>\n\n\n\n<figure class=\"wp-block-image size-large\"><img loading=\"lazy\" decoding=\"async\" width=\"1024\" height=\"181\" src=\"https:\/\/www.freelifemakers.org\/wordpress\/wp-content\/uploads\/2026\/04\/uploads-jpg-1-1024x181.jpg\" alt=\"\" class=\"wp-image-5390\" srcset=\"https:\/\/www.freelifemakers.org\/wordpress\/wp-content\/uploads\/2026\/04\/uploads-jpg-1-1024x181.jpg 1024w, https:\/\/www.freelifemakers.org\/wordpress\/wp-content\/uploads\/2026\/04\/uploads-jpg-1-300x53.jpg 300w, https:\/\/www.freelifemakers.org\/wordpress\/wp-content\/uploads\/2026\/04\/uploads-jpg-1-768x136.jpg 768w, https:\/\/www.freelifemakers.org\/wordpress\/wp-content\/uploads\/2026\/04\/uploads-jpg-1-400x71.jpg 400w, https:\/\/www.freelifemakers.org\/wordpress\/wp-content\/uploads\/2026\/04\/uploads-jpg-1-800x141.jpg 800w, https:\/\/www.freelifemakers.org\/wordpress\/wp-content\/uploads\/2026\/04\/uploads-jpg-1.jpg 1154w\" sizes=\"auto, (max-width: 1024px) 100vw, 1024px\" \/><figcaption class=\"wp-element-caption\">\uc5c5\ub85c\ub4dc \uc0c1\ud0dc \ud655\uc778 \/ Check upload status<\/figcaption><\/figure>\n\n\n\n<p><\/p>\n","protected":false},"excerpt":{"rendered":"<p>\ud83d\udc49\ud83c\udffb \ub300\uc6a9\ub7c9 \ud30c\uc77c \uc5c5\ub85c\ub4dc\ub97c \uc704\ud55c \uc124\uba85\uc785\ub2c8\ub2e4.This is an explanation for uploading large files. \ud83d\udc49\ud83c\udffb \uc5c5\ub85c\ub4dc \uc9c4\ud589\ub960\uc744 \ud655\uc778\uc744 \ud560 \uc218 \uc788\uc2b5\ub2c8\ub2e4.You can check the upload progress. \ud83d\udc49\ud83c\udffb \ud14c\uc2a4\ud2b8\ub294 macOS\uc5d0\uc11c http\ub85c \ud14c\uc2a4\ud2b8 \ud588\uc2b5\ub2c8\ub2e4.The test was performed on macOS using http. \ud83d\udc49\ud83c\udffb macOS\uc5d0\uc11c \ud14c\uc2a4\ud2b8 \ud588\uc9c0\ub9cc \ub9ac\ub205\uc2a4\uc5d0\uc11c \uc0ac\uc6a9\ud574\ub3c4 \ub429\ub2c8\ub2e4.I tested it on macOS, but it can also be used [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[23,1],"tags":[],"class_list":["post-5378","post","type-post","status-publish","format-standard","hentry","category-cpp","category-uncategorized","missing-thumbnail"],"_links":{"self":[{"href":"https:\/\/www.freelifemakers.org\/wordpress\/index.php\/wp-json\/wp\/v2\/posts\/5378","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.freelifemakers.org\/wordpress\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.freelifemakers.org\/wordpress\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.freelifemakers.org\/wordpress\/index.php\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.freelifemakers.org\/wordpress\/index.php\/wp-json\/wp\/v2\/comments?post=5378"}],"version-history":[{"count":10,"href":"https:\/\/www.freelifemakers.org\/wordpress\/index.php\/wp-json\/wp\/v2\/posts\/5378\/revisions"}],"predecessor-version":[{"id":5392,"href":"https:\/\/www.freelifemakers.org\/wordpress\/index.php\/wp-json\/wp\/v2\/posts\/5378\/revisions\/5392"}],"wp:attachment":[{"href":"https:\/\/www.freelifemakers.org\/wordpress\/index.php\/wp-json\/wp\/v2\/media?parent=5378"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.freelifemakers.org\/wordpress\/index.php\/wp-json\/wp\/v2\/categories?post=5378"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.freelifemakers.org\/wordpress\/index.php\/wp-json\/wp\/v2\/tags?post=5378"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}