HGGitLab

Commit 048079a4 authored by luoliangyi's avatar luoliangyi

websdk:增加ofd、pdf、tiff和zip返回base64的功能

parent 7e3b95ca
......@@ -303,35 +303,140 @@ void HttpUser::HandleCmd(const HttpCmdParam* param)
(const HGByte*)result, (HGUInt)strlen(result), "application/json");
}
}
else if (requestMethod == "POST" && requestURIPath == "/WebScan/majorOfd")
{
if (std::string::npos != param->head.GetContentType().find("application/x-www-form-urlencoded"))
{
std::string query((const char*)param->data, param->size);
HttpPairs uriQueryInfos;
HttpHead::AnalysisURIQuery(query.c_str(), uriQueryInfos);
std::string majorOfdParam = HttpHead::GetValue(uriQueryInfos, "formDataString");
std::string devId;
bool isAuto = false;
cJSON* json = cJSON_Parse(majorOfdParam.c_str());
if (NULL != json)
{
devId = GetJsonStringValue(json, "pid");
isAuto = GetJsonBoolValue(json, "isAuto");
cJSON_Delete(json);
}
std::string imgBase64;
GetManager()->ExportOfd(devId, isAuto, imgBase64);
char* result = new char[imgBase64.size() + 256];
sprintf(result, "{\"code\":%d, \"msg\":null, \"data\":%s}", 200, imgBase64.c_str());
SendResponse(requestHttpVersion.c_str(), 200, "OK",
(const HGByte*)result, (HGUInt)strlen(result), "application/json");
delete[] result;
}
}
else if (requestMethod == "GET" && requestURIPath == "/WebScan/majorOfdFile")
{
std::string devId = HttpHead::GetValue(requestURIQueryInfos, "pid");
bool isAuto = ("true" == HttpHead::GetValue(requestURIQueryInfos, "isAuto") ? true : false);
HGByte* data = NULL;
HGUInt size = 0;
GetManager()->ExportOfdFile(&data, &size);
GetManager()->ExportOfdFile(devId, isAuto, &data, &size);
SendResponse(requestHttpVersion.c_str(), 200, "OK", data, size, "application/zip");
delete[] data;
}
else if (requestMethod == "POST" && requestURIPath == "/WebScan/majorPdf")
{
if (std::string::npos != param->head.GetContentType().find("application/x-www-form-urlencoded"))
{
std::string query((const char*)param->data, param->size);
HttpPairs uriQueryInfos;
HttpHead::AnalysisURIQuery(query.c_str(), uriQueryInfos);
std::string majorOfdParam = HttpHead::GetValue(uriQueryInfos, "formDataString");
std::string devId;
cJSON* json = cJSON_Parse(majorOfdParam.c_str());
if (NULL != json)
{
devId = GetJsonStringValue(json, "pid");
cJSON_Delete(json);
}
std::string imgBase64;
GetManager()->ExportPdf(devId, imgBase64);
char* result = new char[imgBase64.size() + 256];
sprintf(result, "{\"code\":%d, \"msg\":null, \"data\":%s}", 200, imgBase64.c_str());
SendResponse(requestHttpVersion.c_str(), 200, "OK",
(const HGByte*)result, (HGUInt)strlen(result), "application/json");
delete[] result;
}
}
else if (requestMethod == "GET" && requestURIPath == "/WebScan/majorPdfFile")
{
std::string devId = HttpHead::GetValue(requestURIQueryInfos, "pid");
HGByte* data = NULL;
HGUInt size = 0;
GetManager()->ExportPdfFile(&data, &size);
GetManager()->ExportPdfFile(devId, &data, &size);
SendResponse(requestHttpVersion.c_str(), 200, "OK", data, size, "application/pdf");
delete[] data;
}
else if (requestMethod == "POST" && requestURIPath == "/WebScan/majorTiff")
{
if (std::string::npos != param->head.GetContentType().find("application/x-www-form-urlencoded"))
{
std::string query((const char*)param->data, param->size);
HttpPairs uriQueryInfos;
HttpHead::AnalysisURIQuery(query.c_str(), uriQueryInfos);
std::string devId = HttpHead::GetValue(uriQueryInfos, "pid");
std::string imgBase64;
GetManager()->ExportTiff(devId, imgBase64);
char* result = new char[imgBase64.size() + 256];
sprintf(result, "{\"code\":%d, \"msg\":null, \"data\":%s}", 200, imgBase64.c_str());
SendResponse(requestHttpVersion.c_str(), 200, "OK",
(const HGByte*)result, (HGUInt)strlen(result), "application/json");
delete[] result;
}
}
else if (requestMethod == "GET" && requestURIPath == "/WebScan/majorTiffFile")
{
std::string devId = HttpHead::GetValue(requestURIQueryInfos, "pid");
HGByte* data = NULL;
HGUInt size = 0;
GetManager()->ExportTiffFile(&data, &size);
GetManager()->ExportTiffFile(devId, &data, &size);
SendResponse(requestHttpVersion.c_str(), 200, "OK", data, size, "application/x-tif");
delete[] data;
}
else if (requestMethod == "GET" && requestURIPath == "/WebScan/downLoadZip")
{
if (std::string::npos != param->head.GetContentType().find("application/x-www-form-urlencoded"))
{
std::string query((const char*)param->data, param->size);
HttpPairs uriQueryInfos;
HttpHead::AnalysisURIQuery(query.c_str(), uriQueryInfos);
std::string devId = HttpHead::GetValue(uriQueryInfos, "pid");
std::string imgBase64;
GetManager()->ExportZip(devId, imgBase64);
char* result = new char[imgBase64.size() + 256];
sprintf(result, "{\"code\":%d, \"msg\":null, \"data\":%s}", 200, imgBase64.c_str());
SendResponse(requestHttpVersion.c_str(), 200, "OK",
(const HGByte*)result, (HGUInt)strlen(result), "application/json");
delete[] result;
}
}
else if (requestMethod == "GET" && requestURIPath == "/WebScan/downLoadZipFile")
{
std::string devId = HttpHead::GetValue(requestURIQueryInfos, "pid");
HGByte* data = NULL;
HGUInt size = 0;
GetManager()->ExportZipFile(&data, &size);
GetManager()->ExportZipFile(devId, &data, &size);
SendResponse(requestHttpVersion.c_str(), 200, "OK", data, size, "application/zip");
delete[] data;
}
......
......@@ -652,7 +652,27 @@ bool Manager::SetDevParam(const std::string& devId, const DevParam& devParam)
return ret;
}
bool Manager::ExportOfdFile(HGByte** data, HGUInt* size)
bool Manager::ExportOfd(const std::string& devId, bool isAuto, std::string& imgBase64)
{
imgBase64.clear();
if (m_scanning)
{
return false;
}
HGByte* data = NULL;
HGUInt size = 0;
ExportOfdFile(devId, isAuto, &data, &size);
if (NULL != data)
{
imgBase64 = GetBase64(data, size);
delete[] data;
}
return !imgBase64.empty();
}
bool Manager::ExportOfdFile(const std::string& devId, bool isAuto, HGByte** data, HGUInt* size)
{
*data = NULL;
*size = 0;
......@@ -661,9 +681,6 @@ bool Manager::ExportOfdFile(HGByte** data, HGUInt* size)
return false;
}
std::string devId;
GetCurDevId(devId);
std::string filePath = GetFilePath(devId);
std::vector<std::string> fileNameList = GetFileNameList(devId);
if (fileNameList.empty())
......@@ -708,7 +725,27 @@ bool Manager::ExportOfdFile(HGByte** data, HGUInt* size)
return (NULL != *data);
}
bool Manager::ExportPdfFile(HGByte** data, HGUInt* size)
bool Manager::ExportPdf(const std::string& devId, std::string& imgBase64)
{
imgBase64.clear();
if (m_scanning)
{
return false;
}
HGByte* data = NULL;
HGUInt size = 0;
ExportPdfFile(devId, &data, &size);
if (NULL != data)
{
imgBase64 = GetBase64(data, size);
delete[] data;
}
return !imgBase64.empty();
}
bool Manager::ExportPdfFile(const std::string& devId, HGByte** data, HGUInt* size)
{
*data = NULL;
*size = 0;
......@@ -717,9 +754,6 @@ bool Manager::ExportPdfFile(HGByte** data, HGUInt* size)
return false;
}
std::string devId;
GetCurDevId(devId);
std::string filePath = GetFilePath(devId);
std::vector<std::string> fileNameList = GetFileNameList(devId);
if (fileNameList.empty())
......@@ -764,7 +798,27 @@ bool Manager::ExportPdfFile(HGByte** data, HGUInt* size)
return (NULL != *data);
}
bool Manager::ExportTiffFile(HGByte** data, HGUInt* size)
bool Manager::ExportTiff(const std::string& devId, std::string& imgBase64)
{
imgBase64.clear();
if (m_scanning)
{
return false;
}
HGByte* data = NULL;
HGUInt size = 0;
ExportTiffFile(devId, &data, &size);
if (NULL != data)
{
imgBase64 = GetBase64(data, size);
delete[] data;
}
return !imgBase64.empty();
}
bool Manager::ExportTiffFile(const std::string& devId, HGByte** data, HGUInt* size)
{
*data = NULL;
*size = 0;
......@@ -773,9 +827,6 @@ bool Manager::ExportTiffFile(HGByte** data, HGUInt* size)
return false;
}
std::string devId;
GetCurDevId(devId);
std::string filePath = GetFilePath(devId);
std::vector<std::string> fileNameList = GetFileNameList(devId);
if (fileNameList.empty())
......@@ -820,7 +871,27 @@ bool Manager::ExportTiffFile(HGByte** data, HGUInt* size)
return (NULL != *data);
}
bool Manager::ExportZipFile(HGByte** data, HGUInt* size)
bool Manager::ExportZip(const std::string& devId, std::string& imgBase64)
{
imgBase64.clear();
if (m_scanning)
{
return false;
}
HGByte* data = NULL;
HGUInt size = 0;
ExportZipFile(devId, &data, &size);
if (NULL != data)
{
imgBase64 = GetBase64(data, size);
delete[] data;
}
return !imgBase64.empty();
}
bool Manager::ExportZipFile(const std::string& devId, HGByte** data, HGUInt* size)
{
*data = NULL;
*size = 0;
......@@ -829,9 +900,6 @@ bool Manager::ExportZipFile(HGByte** data, HGUInt* size)
return false;
}
std::string devId;
GetCurDevId(devId);
std::string filePath = GetFilePath(devId);
std::vector<std::string> fileNameList = GetFileNameList(devId);
if (fileNameList.empty())
......@@ -1376,6 +1444,24 @@ std::string Manager::GetBase64(HGImage image, HGUInt quality)
return strBase64;
}
std::string Manager::GetBase64(const HGByte* data, HGUInt size)
{
std::string strBase64;
if (NULL != data && 0 != size)
{
HGSize base64Size = 0;
HGBase_Base64Encode(data, size, NULL, &base64Size);
uint8_t* base64 = new uint8_t[base64Size + 1];
HGBase_Base64Encode(data, size, base64, &base64Size);
base64[base64Size] = 0;
strBase64 = (const char*)base64;
delete[] base64;
}
return strBase64;
}
std::string Manager::GetBase64(const std::string& fileName)
{
std::string strBase64;
......
......@@ -113,13 +113,17 @@ public:
// 设置配置参数
bool SetDevParam(const std::string& devId, const DevParam& devParam);
// 生成OFD
bool ExportOfdFile(HGByte **data, HGUInt *size);
bool ExportOfd(const std::string& devId, bool isAuto, std::string &imgBase64);
bool ExportOfdFile(const std::string& devId, bool isAuto, HGByte **data, HGUInt *size);
// 生成PDF
bool ExportPdfFile(HGByte** data, HGUInt* size);
bool ExportPdf(const std::string& devId, std::string& imgBase64);
bool ExportPdfFile(const std::string& devId, HGByte** data, HGUInt* size);
// 生成TIFF
bool ExportTiffFile(HGByte** data, HGUInt* size);
bool ExportTiff(const std::string& devId, std::string& imgBase64);
bool ExportTiffFile(const std::string& devId, HGByte** data, HGUInt* size);
// 生成ZIP
bool ExportZipFile(HGByte** data, HGUInt* size);
bool ExportZip(const std::string& devId, std::string& imgBase64);
bool ExportZipFile(const std::string& devId, HGByte** data, HGUInt* size);
// 上传图像
bool UploadImage(const UploadParam& uploadParam);
// 保存图片
......@@ -153,6 +157,7 @@ private:
static std::vector<std::string> GetFileNameList(const std::string &devId);
static bool SaveFileNameList(const std::string& devId, const std::vector<std::string>& fileNameList);
static std::string GetBase64(HGImage image, HGUInt quality);
static std::string GetBase64(const HGByte *data, HGUInt size);
static std::string GetBase64(const std::string& fileName);
static HGByte* GetBuffer(const std::string& fileName, HGUInt *size);
static bool SaveBase64(const std::string& fileName, const char *base64);
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment