In a versioning-enabled bucket, different versions of the objects may have different storage classes. By default, the RestoreObject operation restores the current version of an object. To restore a specific version of the object, specify the version ID.
The following code provides an example on how to restore 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);
/*Restore an object with the Archive storage class.*/
RestoreObjectRequest request(BucketName, ObjectName);
request.setVersionId("yourObjectVersionId");
auto outcome = client.RestoreObject(request);
/*View the version ID of the object to restore.*/
if (outcome.isSuccess()) {
std::cout << "versionid:" << outcome.result().VersionId() << std::endl;
}
else {
/*Handle exceptions.*/
std::cout << "RestoreObject 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 restoring an object, see RestoreObject.