By default, calling the GetObject operation on an object in a versioning-enabled bucket returns only the current version of the object.

When you perform the GetObject operation on an object in a bucket:
  • If the current version of the object is a delete marker, the 4040 Not Found error is returned.
  • If you specify the versionId of the target object in the request, the specified version of the object is returned. For example, if the versionId is specified as null in the request, the version of which the versionId is null is returned.
  • If the version specified in the request is a delete marker, the 405 Method Not Allowed error is returned.

The following code provides an example on how to download an object:

#include <alibabacloud/oss/OssClient.h>
using namespace AlibabaCloud::OSS;

int main(void)
{
    /*Initialize the OSS account information.*/
    std::string AccessKeyId = "yourAccessKeyId";
    std::string AccessKeySecret = "yourAccessKeySecret";
    std::string Endpoint = "yourEndpoint";
    std::string BucketName = "yourBucketName";
    std::string ObjectName = "yourObjectName";

    /*Initialize network resources.*/
    InitializeSdk();

    ClientConfiguration conf;
    OssClient client(Endpoint, AccessKeyId, AccessKeySecret, conf);

    /*Download an object to local memory.*/
    GetObjectRequest request(BucketName, ObjectName);
    request.setVersionId("yourObjectVersionId");
    auto outcome = client.GetObject(request);
    if (outcome.isSuccess()) {
        std::cout << "getObjectToBuffer" << " success, Content-Length:" << outcome.result().Metadata().ContentLength() << std::endl;
        /*Read the content of the downloaded object.*/
        std::string content;
        *(outcome.result().Content()) >> content;
        std::cout << "getObjectToBuffer" << "content:" << content << std::endl;
        /*View the version ID of the downloaded object.*/
        std::cout << "versionid:" << outcome.result().VersionId() << std::endl;
    }
    else {
            /*Handle exceptions.*/
            std::cout << "getObjectToBuffer fail" <<
        ",code:" << outcome.error().Code() <<
        ",message:" << outcome.error().Message() <<
        ",requestId:" << outcome.error().RequestId() << std::endl;
            ShutdownSdk();
            return -1;
    }

    /*Release network resources.*/
    ShutdownSdk();
    return 0;
}

For more information about downloading objects, see GetObject.