From 006eece147cf06d12b5a41b327cbb194645e1370 Mon Sep 17 00:00:00 2001 From: YuLi Date: Sat, 1 Aug 2026 22:04:57 -0700 Subject: [PATCH] =?UTF-8?q?=E4=BC=98=E5=8C=96http=E6=96=87=E4=BB=B6?= =?UTF-8?q?=E4=B8=8A=E4=BC=A0=E7=9B=B8=E5=85=B3=E4=BB=A3=E7=A0=81=20(#4796?= =?UTF-8?q?)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- server/WebApi.cpp | 2 ++ src/Http/HttpBody.cpp | 4 ++-- src/Http/HttpBody.h | 8 ++++++-- 3 files changed, 10 insertions(+), 4 deletions(-) diff --git a/server/WebApi.cpp b/server/WebApi.cpp index 0cef58c6..e11adb72 100755 --- a/server/WebApi.cpp +++ b/server/WebApi.cpp @@ -226,6 +226,8 @@ static std::map s_map_file_handler * Register a handler for a URL path. When a PUT/POST request arrives at that path, * the handler is invoked to create an HttpBody (e.g. HttpFileStorage) that receives * the request body stream directly. CHECK_SECRET() can be used inside the handler. + * File publication policy belongs to the registered application: use a temporary + * storage path here and move it to the public path in the corresponding API handler. * * @param url_path the HTTP URL path to match * @param handler callback that sets body; may throw AuthException to reject diff --git a/src/Http/HttpBody.cpp b/src/Http/HttpBody.cpp index c46af49a..2c252f92 100644 --- a/src/Http/HttpBody.cpp +++ b/src/Http/HttpBody.cpp @@ -147,7 +147,7 @@ static std::shared_ptr getSharedMmap(const string &file_path, int64_t &fil return nullptr; } - LARGE_INTEGER FileSize; + LARGE_INTEGER FileSize; GetFileSizeEx(hfile, &FileSize); //GetFileSize函数的拓展,可用于获取大于4G的文件大小 file_size = FileSize.QuadPart; @@ -202,7 +202,7 @@ HttpFileBody::HttpFileBody(const string &file_path, bool use_mmap) { } if (use_mmap ) { - _map_addr = getSharedMmap(file_path, _read_to); + _map_addr = getSharedMmap(file_path, _read_to); } if (!_map_addr && _read_to != -1) { diff --git a/src/Http/HttpBody.h b/src/Http/HttpBody.h index 0d46e4e1..6a0d230d 100644 --- a/src/Http/HttpBody.h +++ b/src/Http/HttpBody.h @@ -211,11 +211,15 @@ public: using Ptr = std::shared_ptr; /** - * @param file_path 文件路径,文件以二进制写入模式打开(覆盖已有内容) - * @param file_path File path, opened in binary write mode (truncates existing content) + * @param file_path 直接以二进制覆盖写入的路径;未完成的上传会删除该路径。需要保护正式文件时,调用方应 + * 传入临时路径,并在请求处理完成后自行发布到正式路径。 + * @param file_path Path opened directly in binary truncate mode and removed after an incomplete upload. To protect + * a published file, pass a temporary path and publish it from the completed-request handler. */ HttpFileStorage(std::string file_path); ~HttpFileStorage() override; + HttpFileStorage(const HttpFileStorage &) = delete; + HttpFileStorage &operator=(const HttpFileStorage &) = delete; void writeData(const char *data, size_t size, uint64_t content_size) override; int64_t remainSize() override;