进度条
进度条用于指示上传或下载的进度。
下载进度条的完整代码请参见GitHub。
以下代码展示如何使用进度条:
#include <alibabacloud/oss/OssClient.h>
using namespace AlibabaCloud::OSS;
void ProgressCallback(size_t increment, int64_t transfered, int64_t total, void* userData)
{
std::cout << "ProgressCallback[" << userData << "] => " <<
increment <<" ," << transfered << "," << total << std::endl;
}
int main(void )
{
/* 初始化OSS账号信息 */
std::string AccessKeyId = "yourAccessKeyId";
std::string AccessKeySecret = "yourAccessKeySecret";
std::string Endpoint = "yourEndpoint";
std::string BucketName = "yourBucketName";
std::string ObjectName = "yourObjectName" ;
/* 初始化网络等资源 */
InitializeSdk();
ClientConfiguration conf;
OssClient client(Endpoint, AccessKeyId, AccessKeyS ecre t, conf);
/* 获取文件 */
GetObjectRequest request(BucketName, ObjectName);
TransferProgress progressCallback = { ProgressCallback , nullptr };
request.setTransferProgress(progressCallback);
auto outcome = client.GetObject(request);
if (!outcome.isSuccess()) {
/* 异常处理 */
std::cout << "getObject fail" <<
",code:" << outcome.error().Code() <<
",message:" << outcome.error().Message() <<
",requestId:" << outcome.error().RequestId() << std::endl;
ShutdownSdk ();
return -1;
}
/* 释放网络等资源 */
ShutdownSdk();
return 0;
}
版权声明
本文仅代表作者观点,不代表本站立场。
本文系作者授权发表,未经许可,不得转载。
评论