remove file after upload

This commit is contained in:
lnk
2026-05-22 11:34:14 +08:00
parent c6ca57a204
commit c388bd04fe
3 changed files with 3874 additions and 2 deletions

View File

@@ -5332,7 +5332,7 @@ std::string base64_encode(const std::string& in) {
return out; // 返回编码后的字符串
}
void handleUploadResponse(const std::string& response, char* wavepath, int type) {
void handleUploadResponse(const std::string& response,const std::string& localPath, char* wavepath, int type) {
// 解析 JSON 响应
cJSON* json_data = cJSON_Parse(response.c_str());
@@ -5390,6 +5390,33 @@ void handleUploadResponse(const std::string& response, char* wavepath, int type)
std::cout << "wavepath: " << wavepath << std::endl;
DIY_INFOLOG_CODE("process",0,LOG_CODE_TRANSIENT_COMM,"【NORMAL】前置上传文件成功,远端文件名:%s",wavepath);
// =========================
// 上传成功后删除本地文件
// =========================
if (remove(localPath.c_str()) == 0)
{
std::cout << "Delete local file success: "
<< localPath << std::endl;
DIY_INFOLOG_CODE("process",0,
LOG_CODE_TRANSIENT_COMM,
"【NORMAL】删除本地文件成功:%s",
localPath.c_str());
}
else
{
std::cout << "Delete local file failed: "
<< localPath
<< " errno=" << errno
<< " err=" << strerror(errno)
<< std::endl;
DIY_ERRORLOG_CODE("process",0,
LOG_CODE_TRANSIENT_COMM,
"【ERROR】删除本地文件失败:%s errno=%d err=%s",
localPath.c_str(),
errno,
strerror(errno));
}
}
} else {
std::cerr << "Error: Missing expected fields in JSON response." << std::endl;
@@ -5513,7 +5540,7 @@ void SendFileWeb(const std::string& strUrl, const char* localpath, const char* c
DIY_ERRORLOG_CODE("process",0,LOG_CODE_TRANSIENT_COMM,"【ERROR】前置上传暂态录波文件 %s 失败,请检查文件上传接口配置",localpath);
} else {
std::cout << "http web success, response: " << resPost0 << std::endl;
handleUploadResponse(resPost0, wavepath, type); // 处理响应
handleUploadResponse(resPost0, localpath, wavepath, type); // 处理响应
}
// 清理