diff --git a/mongoose.c b/mongoose.c
index 7c1529a9dc3323d14096d304a1119ace9203f352..a29539e7389f35afb3d9fd0754d8ffefad36eb71 100644
--- a/mongoose.c
+++ b/mongoose.c
@@ -4191,7 +4191,8 @@ int mg_upload(struct mg_connection *conn, const char *destination_dir) {
         if (!memcmp(&buf[i], "\r\n--", 4) &&
             !memcmp(&buf[i + 4], boundary, boundary_len)) {
           // Found boundary, that's the end of file data.
-          (void) fwrite(buf, 1, i, fp);
+          fwrite(buf, 1, i, fp);
+          fflush(fp);
           num_uploaded_files++;
           conn->request_info.ev_data = (void *) path;
           call_user(conn, MG_UPLOAD);