您可以在上传过程中的任意时间节点中断上传。

以下代码用于中断上传:
#include <alibabacloud/oss/OssClient.h>
#include <fstream>
using namespace AlibabaCloud::OSS;

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, AccessKeySecret, conf);
    std::vector<PutObjectOutcomeCallable> Callables;
    for (int i=0; i < 4; i++)  {  
        std::shared_ptr<std::iostream> content = std::make_shared<std::fstream>("yourLocalFilename", std::ios::in|std::ios::binary);
        PutObjectRequest request(BucketName, ObjectName, content);
        auto outcomeCallable = client.PutObjectCallable(request);
        Callables.emplace_back(std::move(outcomeCallable));
    }
    std::this_thread::sleep_for(std::chrono::milliseconds(1000));

    /* 中断上传 */
    client.DisableRequest();

    for (size_t i = 0; i < Callables.size(); i++) {
        auto outcome = Callables[i].get();
        if (outcome.error().Code() == "ClientError:100002" ||
        outcome.error().Code() == "ClientError:200042") {
            std::cout << "disable putobject success" << std::endl;
        }
    }

    /* 释放网络等资源 */
    ShutdownSdk();
    return 0;
}
说明 中断上传与取消分片上传区别如下:
  • 中断上传是指开发者调用上传接口向远程 OSS 上传文件时,停掉了该调用任务,即取消了本次上传任务。取消分片上传是指通知 OSS 不再接受该 UploadID 的分片上传任务。
  • 若进行分片上传任务,中断上传将导致本次分片上传任务被取消,您仍然可以调用该 UploadID 重新上传。若取消分片上传后,则该 UploadID 将不可用。
  • 中断上传对所有接口均有效。取消分片上传只针对分片上传有效。