在受版本控制的存储空间(Bucket)中,文件(Object)的各个版本可以对应不同的存储类型。RestoreObject接口默认解冻Object的当前版本,允许通过指定versionId的方式来解冻指定版本的Object。

以下代码用于解冻文件:

using Aliyun.OSS;
using Aliyun.OSS.Model;
var endpoint = "<yourEndpoint>";
var accessKeyId = "<yourAccessKeyId>";
var accessKeySecret = "<yourAccessKeySecret>";
var bucketName = "<yourBucketName>";
var objectName = "<yourObjectName>";
var objectContent = "More than just cloud.";
var versionid = "<yourArchiveObjectVersionid>";
int maxWaitTimeInSeconds = 600;
// 创建OssClient实例。
var client = new OssClient(endpoint, accessKeyId, accessKeySecret);
var getrequest = new GetObjectMetadataRequest(bucketName, objectName)
{
    // 指定归档类型Object的版本id。
    VersionId = versionid   
};
var metadata = client.GetObjectMetadata(getrequest);
string storageClass = metadata.HttpMetadata["x-oss-storage-class"] as string;
if (storageClass != "Archive")
{
    Console.WriteLine("StorageClass is {0}", storageClass);
    return;
}
// 解冻文件。
var request = new RestoreObjectRequest(bucketName, objectName)
{   
    // 指定归档类型Object的版本id。
    VersionId = versionid
};
RestoreObjectResult result = client.RestoreObject(request);
Console.WriteLine("RestoreObject result HttpStatusCode : {0}, versionid: {1}", result.HttpStatusCode, result.VersionId);
if (result.HttpStatusCode != HttpStatusCode.Accepted)
{
    throw new OssException(result.RequestId + ", " + result.HttpStatusCode + " ,");
}
while (maxWaitTimeInSeconds > 0)
{
    var req = new GetObjectMetadataRequest(bucketName, objectName)
    {
        // 指定归档类型Object的版本id。
        VersionId = versionid   
    };
    var meta = client.GetObjectMetadata(req);
    string restoreStatus = meta.HttpMetadata["x-oss-restore"] as string;
    if (restoreStatus != null && restoreStatus.StartsWith("ongoing-request=\"false\"", StringComparison.InvariantCultureIgnoreCase))
    {
        break;
    }
    Thread.Sleep(1000);
    maxWaitTimeInSeconds--;
}
if (maxWaitTimeInSeconds == 0)
{
    Console.WriteLine("RestoreObject is timeout. ");
    throw new TimeoutException();
}
else
{
    Console.WriteLine("RestoreObject is successful. ");
}

解冻文件的详细信息请参见RestoreObject