diff --git a/LFtid1056/cloudfront/code/interface.cpp b/LFtid1056/cloudfront/code/interface.cpp index eae6bf3..3cda132 100644 --- a/LFtid1056/cloudfront/code/interface.cpp +++ b/LFtid1056/cloudfront/code/interface.cpp @@ -25,7 +25,7 @@ #include "interface.h" #include "rocketmq.h" #include "nlohmann/json.hpp" -#include "log4cplus/log4.h" +#include "log4.h" //////////////////////////////////////////////////////////////////////////////////////////////////////////////// @@ -200,9 +200,28 @@ void handleUploadResponse(const std::string& response, std::string& wavepath) { //上传文件 void SendFileWeb(const std::string& strUrl, const std::string& localpath, const std::string& cloudpath, std::string& wavepath) { + + // 基本存在性检查 + if (access(localpath.c_str(), F_OK) != 0) { + std::cerr << "Local file does not exist: " << localpath << std::endl; + return; + } + // ★新增:stat 打印大小,便于快速确认读源 + struct stat st {}; + if (stat(localpath.c_str(), &st) != 0) { + perror("stat"); + } else { + std::cout << "[debug] upload file: " << localpath + << ", size=" << static_cast(st.st_size) << " bytes\n"; + } + // 初始化 curl CURL* curl = curl_easy_init(); if (curl) { + // ★新增:错误缓冲,便于看到更具体的错误 + char errbuf[CURL_ERROR_SIZE] = {0}; + curl_easy_setopt(curl, CURLOPT_ERRORBUFFER, errbuf); // ★新增 + // 设置请求 URL 和 POST 请求 curl_easy_setopt(curl, CURLOPT_URL, strUrl.c_str()); curl_easy_setopt(curl, CURLOPT_POST, 1); @@ -211,21 +230,16 @@ void SendFileWeb(const std::string& strUrl, const std::string& localpath, const curl_httppost* formpost = nullptr; curl_httppost* lastptr = nullptr; - if (access(localpath.c_str(), F_OK) != 0) { - std::cerr << "Local file does not exist: " << localpath << std::endl; - return; - } - // 添加文件字段,直接从本地路径读取文件内容 curl_formadd(&formpost, &lastptr, CURLFORM_COPYNAME, "file", - CURLFORM_FILE, localpath, + CURLFORM_FILE, localpath.c_str(), CURLFORM_END); // 添加 `path` 字段 curl_formadd(&formpost, &lastptr, CURLFORM_COPYNAME, "path", - CURLFORM_COPYCONTENTS, cloudpath, + CURLFORM_COPYCONTENTS, cloudpath.c_str(), CURLFORM_END); // 添加 `isReserveName` 字段 @@ -238,13 +252,14 @@ void SendFileWeb(const std::string& strUrl, const std::string& localpath, const curl_easy_setopt(curl, CURLOPT_HTTPPOST, formpost); // 设置头信息 - struct curl_slist* header_list = nullptr; - header_list = curl_slist_append(header_list, "Content-Type: multipart/form-data"); - curl_easy_setopt(curl, CURLOPT_HTTPHEADER, header_list); + //struct curl_slist* header_list = nullptr; + //header_list = curl_slist_append(header_list, "Content-Type: multipart/form-data"); + //curl_easy_setopt(curl, CURLOPT_HTTPHEADER, header_list); // 设置超时时间 curl_easy_setopt(curl, CURLOPT_CONNECTTIMEOUT, 10); curl_easy_setopt(curl, CURLOPT_TIMEOUT, 10); + curl_easy_setopt(curl, CURLOPT_NOSIGNAL, 1L); // ★新增:避免多线程环境下超时触发信号 // 设置写入响应数据的函数 std::string resPost0; @@ -254,7 +269,8 @@ void SendFileWeb(const std::string& strUrl, const std::string& localpath, const // 执行请求 CURLcode res = curl_easy_perform(curl); if (res != CURLE_OK) { - std::cerr << "http web failed: " << curl_easy_strerror(res) << std::endl; + const char* em = errbuf[0] ? errbuf : curl_easy_strerror(res); + std::cerr << "http web failed: " << em << std::endl; DIY_ERRORLOG("process","【ERROR】前置上传暂态录波文件 %s 失败,请检查文件上传接口配置",localpath); } else { std::cout << "http web success, response: " << resPost0 << std::endl; @@ -263,7 +279,7 @@ void SendFileWeb(const std::string& strUrl, const std::string& localpath, const // 清理 curl_formfree(formpost); // 释放表单数据 - curl_slist_free_all(header_list); // 释放头部列表 + //curl_slist_free_all(header_list); // 释放头部列表 curl_easy_cleanup(curl); } else { std::cerr << ">>> curl init failed" << std::endl; diff --git a/LFtid1056/cloudfront/code/log4.cpp b/LFtid1056/cloudfront/code/log4.cpp index 3c26009..d86b519 100644 --- a/LFtid1056/cloudfront/code/log4.cpp +++ b/LFtid1056/cloudfront/code/log4.cpp @@ -24,12 +24,11 @@ #include "log4cplus/fileappender.h" #include "log4cplus/layout.h" #include "log4cplus/ndc.h" -#include "log4cplus/log4.h" #include "log4cplus/spi/loggingevent.h" #include "rocketmq.h" #include "interface.h" -#include "log4cplus/log4.h" +#include "log4.h" ///////////////////////////////////////////////////////////////////////////////////////////////////////////// //log4命名空间 diff --git a/LFtid1056/cloudfront/code/log4.h b/LFtid1056/cloudfront/code/log4.h index d9d620c..ec52585 100644 --- a/LFtid1056/cloudfront/code/log4.h +++ b/LFtid1056/cloudfront/code/log4.h @@ -184,7 +184,7 @@ typedef enum LogCode { // ★新增:显式传入 code 的便捷宏 // 用法示例:DIY_WARNLOG_CODE(full_key_m_c, warn_recallstart, "【WARN】监测点:%s ...", ...); -#define DIY_ERRORLOG_CODE(KEY, LEVEL_INT,CODE_INT, ...) DIY_LOG_CODE(log_error, KEY,LEVEL_INT, CODE_INT, __VA_ARGS__) // ★新增 +#define DIY_ERRORLOG_CODE(KEY, LEVEL_INT,CODE_INT, ...) DIY_LOG_CODE(log_error, KEY, LEVEL_INT, CODE_INT, __VA_ARGS__) // ★新增 #define DIY_WARNLOG_CODE(KEY, LEVEL_INT,CODE_INT, ...) DIY_LOG_CODE(log_warn, KEY, LEVEL_INT, CODE_INT, __VA_ARGS__) // ★新增 #define DIY_INFOLOG_CODE(KEY, LEVEL_INT,CODE_INT, ...) DIY_LOG_CODE(log_info, KEY, LEVEL_INT, CODE_INT, __VA_ARGS__) // ★新增 #define DIY_DEBUGLOG_CODE(KEY, LEVEL_INT,CODE_INT, ...) DIY_LOG_CODE(log_debug, KEY, LEVEL_INT, CODE_INT, __VA_ARGS__) // ★新增 diff --git a/LFtid1056/cloudfront/code/main.cpp b/LFtid1056/cloudfront/code/main.cpp index 82e5422..8adc8cf 100644 --- a/LFtid1056/cloudfront/code/main.cpp +++ b/LFtid1056/cloudfront/code/main.cpp @@ -29,7 +29,7 @@ //////////////////////////////////////////////////////////////////////////////////////////////////////// #include "interface.h" //用于访问接口 -#include "log4cplus/log4.h" //用于日志 +#include "log4.h" //用于日志 #include "curl/curl.h" //用于访问接口 #include "nlohmann/json.hpp" //用于构造json #include "worker.h" //shell接口 diff --git a/LFtid1056/cloudfront/code/rocketmq.cpp b/LFtid1056/cloudfront/code/rocketmq.cpp index 870c355..e00f370 100644 --- a/LFtid1056/cloudfront/code/rocketmq.cpp +++ b/LFtid1056/cloudfront/code/rocketmq.cpp @@ -33,7 +33,7 @@ #include "rocketmq.h" #include "nlohmann/json.hpp" -#include "log4cplus/log4.h" +#include "log4.h" #include "interface.h" #include "front.h" diff --git a/LFtid1056/cloudfront/code/worker.cpp b/LFtid1056/cloudfront/code/worker.cpp index 7aa675b..5f6d6ef 100644 --- a/LFtid1056/cloudfront/code/worker.cpp +++ b/LFtid1056/cloudfront/code/worker.cpp @@ -35,7 +35,7 @@ #include "worker.h" #include "interface.h" #include "rocketmq.h" -#include "log4cplus/log4.h" +#include "log4.h" #include "front.h" /////////////////////////////////////////////////////////////////////////////////////////////////////