累计更新:
cos上传 补丁压缩
This commit is contained in:
@@ -1,7 +1,7 @@
|
||||
#include "sgu_stdafx.h"
|
||||
#include "sgu_download_cos.h"
|
||||
|
||||
#if 1
|
||||
#if 0
|
||||
bool downloadFileFromCOS(const char* cosFilePathName, const char* localFilePath)
|
||||
{
|
||||
return true;
|
||||
@@ -19,15 +19,21 @@ static void TestLogCallback(const std::string& log)
|
||||
//
|
||||
// https://console.cloud.tencent.com/cam/capi
|
||||
//
|
||||
const uint64_t gAppID = 1313389434ULL;
|
||||
const std::string gSecretId = "AKIDGMFKI2av3g6JPTKzRffS1NWR9eXDgwym";
|
||||
const std::string gSecretKey = "f7LMDtNdnlXDpEQRGxVqxrbBYjlcbP2U";
|
||||
const std::string gRegion = "ap-shanghai";
|
||||
const std::string gBucketName = "dnftest-1313389434";
|
||||
//const uint64_t gAppID = 1313389434ULL;
|
||||
//const std::string gSecretId = "AKIDGMFKI2av3g6JPTKzRffS1NWR9eXDgwym";
|
||||
//const std::string gSecretKey = "f7LMDtNdnlXDpEQRGxVqxrbBYjlcbP2U";
|
||||
//const std::string gRegion = "ap-shanghai";
|
||||
//const std::string gBucketName = "dnftest-1313389434";
|
||||
|
||||
|
||||
const std::string gSecretId = "AKIDfBzQo25vgJl170rV1LRNLExTp27GZhho";
|
||||
const std::string gSecretKey = "2qvqX0FKCrHkBQehYDe2JaggePA4nLir";
|
||||
const std::string gRegion = "ap-nanjing";
|
||||
const std::string gBucketName = "client-fwf-1258765125";
|
||||
|
||||
bool downloadFileFromCOS(const char* cosFilePathName, const char* localFilePath)
|
||||
{
|
||||
qcloud_cos::CosConfig config(gAppID, gSecretId, gSecretKey, gRegion);
|
||||
qcloud_cos::CosConfig config(0, gSecretId, gSecretKey, gRegion);
|
||||
config.SetLogCallback(&TestLogCallback);
|
||||
qcloud_cos::CosAPI cos(config);
|
||||
|
||||
@@ -57,4 +63,35 @@ bool downloadFileFromCOS(const char* cosFilePathName, const char* localFilePath)
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
bool uploadFileToCos(const char* localFilePath, const char* cosFilePath)
|
||||
{
|
||||
qcloud_cos::CosConfig config(0, gSecretId, gSecretKey, gRegion);
|
||||
config.SetLogCallback(&TestLogCallback);
|
||||
qcloud_cos::CosAPI cos(config);
|
||||
|
||||
// 构造下载对象的请求
|
||||
std::string objectName = cosFilePath;
|
||||
std::string localPath = localFilePath;
|
||||
|
||||
// 上传对象构造
|
||||
qcloud_cos::PutObjectByFileReq req(gBucketName, objectName, localPath);
|
||||
qcloud_cos::PutObjectByFileResp resp;
|
||||
qcloud_cos::CosResult result = cos.PutObject(req, &resp);
|
||||
if (result.IsSucc()) {
|
||||
// 上传文件成功
|
||||
std::cout << "Upload file success!" << std::endl;
|
||||
}
|
||||
else {
|
||||
// 上传文件失败,可以调用 CosResult 的成员函数输出错误信息,例如 requestID 等
|
||||
std::cout << "HttpStatus=" << result.GetHttpStatus() << std::endl;
|
||||
std::cout << "ErrorCode=" << result.GetErrorCode() << std::endl;
|
||||
std::cout << "ErrorMsg=" << result.GetErrorMsg() << std::endl;
|
||||
std::cout << "ResourceAddr=" << result.GetResourceAddr() << std::endl;
|
||||
std::cout << "XCosRequestId=" << result.GetXCosRequestId() << std::endl;
|
||||
std::cout << "XCosTraceId=" << result.GetXCosTraceId() << std::endl;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
#endif
|
||||
Reference in New Issue
Block a user