断点续传

使用本地文件对文件(object)进行断点续传。在上传时可以指定目录储存记录点,以便在上传失败后恢复上传任务。代码中需要引用"inspurcloud/oss/OssClient.h"类库,使用InspurCloud::OSS命名空间,并初始化账号信息AccessKeyId、AccessKeySecret、UploadFilePath和CheckpointFilePath,示例代码:

        //指定上传到的存储桶、需要上传的文件(Object)、被上传文件的路径以及分片上传结果记录文件(CheckPointFile)的路径
        std::string BucketName = "yourBucketName";
        std::string ObjectName = "yourObjectName";
        //"yourUploadFilePath"以及"yourCheckPointFilePath"需要包含本地路径,例如C:/Users/NAME/Desktop/abc.txt
        std::string UploadFilePath = "yourUploadFilePath";
        std::string CheckpointFilePath = "yourCheckPointFilePath";

        //初始化资源
        InitializeSdk();
        ClientConfiguration conf;
        OssClient client(Endpoint, AccessKeyId, AccessKeySecret, conf);

        //创建请求
        UploadObjectRequest request(BucketName, ObjectName, UploadFilePath, CheckpointFilePath);
        auto result = client.ResumableUploadObject(request);

        //处理结果
        if (!result.isSuccess()) {
            std::cout << "AppendObject fail" << std::endl;
            std::cout << "error code:" << result.error().Code() << std::endl;
            std::cout << "error message:" << result.error().Message() << std::endl;
            std::cout << "requestId:" << result.error().RequestId() << std::endl;
            ShutdownSdk();
            return -1;
        }
        else {
            std::cout << "Resumale upload Object success!" << std::endl;
        }

        //释放资源
        ShutdownSdk();