|
@@ -14,17 +14,16 @@
|
|
#include <vector>
|
|
#include <vector>
|
|
|
|
|
|
using namespace qcloud_cos;
|
|
using namespace qcloud_cos;
|
|
-
|
|
|
|
CosConfig g_config;
|
|
CosConfig g_config;
|
|
|
|
|
|
void result2ufileError(ufile_error & retError, qcloud_cos::CosResult tRet)
|
|
void result2ufileError(ufile_error & retError, qcloud_cos::CosResult tRet)
|
|
{
|
|
{
|
|
- retError.errorCode = tRet.GetErrorCode().c_str();
|
|
|
|
- retError.errorMessage = tRet.GetErrorMsg().c_str();
|
|
|
|
|
|
+ retError.errorCode = tRet.GetErrorCode();
|
|
|
|
+ retError.errorMessage = tRet.GetErrorMsg();
|
|
|
|
+ retError.resourceAddr = tRet.GetResourceAddr();
|
|
|
|
+ retError.cosRequestId = tRet.GetXCosRequestId();
|
|
|
|
+ retError.cosTraceId = tRet.GetXCosTraceId();
|
|
retError.httpStatus = tRet.GetHttpStatus();
|
|
retError.httpStatus = tRet.GetHttpStatus();
|
|
- retError.resourceAddr = tRet.GetResourceAddr().c_str();
|
|
|
|
- retError.cosRequestId = tRet.GetXCosRequestId().c_str();
|
|
|
|
- retError.cosTraceId = tRet.GetXCosTraceId().c_str();
|
|
|
|
retError.bIsSuccess = tRet.IsSucc();
|
|
retError.bIsSuccess = tRet.IsSucc();
|
|
}
|
|
}
|
|
|
|
|
|
@@ -32,17 +31,14 @@ ufile_error ufile_load_config_from_json(const char * json_buf, ufile_config * cf
|
|
{
|
|
{
|
|
ufile_error retError;
|
|
ufile_error retError;
|
|
if (nullptr == cfg)
|
|
if (nullptr == cfg)
|
|
- {
|
|
|
|
- retError.bIsSuccess = false;
|
|
|
|
return retError;
|
|
return retError;
|
|
- }
|
|
|
|
Poco::JSON::Parser parser;
|
|
Poco::JSON::Parser parser;
|
|
Poco::Dynamic::Var result;
|
|
Poco::Dynamic::Var result;
|
|
try {
|
|
try {
|
|
result = parser.parse(json_buf);
|
|
result = parser.parse(json_buf);
|
|
}
|
|
}
|
|
catch (Poco::JSON::JSONException& jsonErr) {
|
|
catch (Poco::JSON::JSONException& jsonErr) {
|
|
- retError.errorMessage = jsonErr.message().c_str();
|
|
|
|
|
|
+ retError.errorMessage = jsonErr.message();
|
|
retError.bIsSuccess = false;
|
|
retError.bIsSuccess = false;
|
|
return retError;
|
|
return retError;
|
|
}
|
|
}
|
|
@@ -118,8 +114,8 @@ ufile_error ufile_put_file_by_filepath(const char * bucket_name, const char * ke
|
|
{
|
|
{
|
|
UNUSED_PARAM(mime_type);
|
|
UNUSED_PARAM(mime_type);
|
|
ufile_error retError;
|
|
ufile_error retError;
|
|
- PutObjectByFileReq req(bucket_name, key, file_path);
|
|
|
|
- PutObjectByFileResp resp;
|
|
|
|
|
|
+ qcloud_cos::PutObjectByFileReq req(bucket_name, key, file_path);
|
|
|
|
+ qcloud_cos::PutObjectByFileResp resp;
|
|
CosAPI cosApi(g_config);
|
|
CosAPI cosApi(g_config);
|
|
CosResult result = cosApi.PutObject(req, &resp);
|
|
CosResult result = cosApi.PutObject(req, &resp);
|
|
result2ufileError(retError, result);
|
|
result2ufileError(retError, result);
|
|
@@ -133,8 +129,8 @@ void set_upload_company(int company)
|
|
ufile_error ufile_delete(const char * bucket_name, const char * key)
|
|
ufile_error ufile_delete(const char * bucket_name, const char * key)
|
|
{
|
|
{
|
|
ufile_error retError;
|
|
ufile_error retError;
|
|
- DeleteObjectReq req(bucket_name, key);
|
|
|
|
- DeleteObjectResp resp;
|
|
|
|
|
|
+ qcloud_cos::DeleteObjectReq req(bucket_name, key);
|
|
|
|
+ qcloud_cos::DeleteObjectResp resp;
|
|
CosAPI cosApi(g_config);
|
|
CosAPI cosApi(g_config);
|
|
CosResult result = cosApi.DeleteObject(req, &resp);
|
|
CosResult result = cosApi.DeleteObject(req, &resp);
|
|
result2ufileError(retError, result);
|
|
result2ufileError(retError, result);
|
|
@@ -171,12 +167,11 @@ ufile_error ufile_download(const char * bucket_name, const char * key, FILE * fi
|
|
if (nullptr == file)
|
|
if (nullptr == file)
|
|
{
|
|
{
|
|
retError.errorMessage = "file is nullptr";
|
|
retError.errorMessage = "file is nullptr";
|
|
- retError.bIsSuccess = false;
|
|
|
|
return retError;
|
|
return retError;
|
|
}
|
|
}
|
|
std::ostringstream os;
|
|
std::ostringstream os;
|
|
- GetObjectByStreamReq req(bucket_name, key, os);
|
|
|
|
- GetObjectByStreamResp resp;
|
|
|
|
|
|
+ qcloud_cos::GetObjectByStreamReq req(bucket_name, key, os);
|
|
|
|
+ qcloud_cos::GetObjectByStreamResp resp;
|
|
CosAPI cosApi(g_config);
|
|
CosAPI cosApi(g_config);
|
|
CosResult result = cosApi.GetObject(req, &resp);
|
|
CosResult result = cosApi.GetObject(req, &resp);
|
|
if (result.IsSucc())
|
|
if (result.IsSucc())
|
|
@@ -203,8 +198,8 @@ ufile_error ufile_bucket_create(const char * bucket_name, const char * region, c
|
|
ufile_error ufile_bucket_delete(const char * bucket_name)
|
|
ufile_error ufile_bucket_delete(const char * bucket_name)
|
|
{
|
|
{
|
|
ufile_error retError;
|
|
ufile_error retError;
|
|
- DeleteBucketReq req(bucket_name);
|
|
|
|
- DeleteBucketResp resp;
|
|
|
|
|
|
+ qcloud_cos::DeleteBucketReq req(bucket_name);
|
|
|
|
+ qcloud_cos::DeleteBucketResp resp;
|
|
CosAPI cosApi(g_config);
|
|
CosAPI cosApi(g_config);
|
|
CosResult result = cosApi.DeleteBucket(req, &resp);
|
|
CosResult result = cosApi.DeleteBucket(req, &resp);
|
|
result2ufileError(retError, result);
|
|
result2ufileError(retError, result);
|