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:

using Aliyun.OSS;
var endpoint = "<yourEndpoint>";
var accessKeyId = "<yourAccessKeyId>";
var accessKeySecret = "<yourAccessKeySecret>";
var bucketName = "<yourBucketName>";
// You must set objectName to the name of the object to download. Example: abc/efg/123.jpg.
var objectName = "<yourObjectName>";
var downloadFilename = "<yourDownloadFilename>";
var versionid = "<yourArchiveObjectVersionid>";
// Create an OSSClient instance.
var client = new OssClient(endpoint, accessKeyId, accessKeySecret);
try
{
    // Download an object to a stream. OssObject includes object information such as the bucket where the object is stored, object name, object metadata, and an input stream.
    var request = new GetObjectRequest(bucketName, objectName)
    {
        // Specify the version ID of the object.
        VersionId = versionid
    };
    var obj = client.GetObject(request);
    using (var requestStream = obj.Content)
    {
        byte[] buf = new byte[1024];
        var fs = File.Open(downloadFilename, FileMode.OpenOrCreate);
        var len = 0;
        // The input stream can be used to read and download the object content to a local file or to the buffer.
        while ((len = requestStream.Read(buf, 0, 1024)) ! = 0)
        {
            fs.Write(buf, 0, len);
        }
        fs.Close();
    }
    Console.WriteLine("Get object succeeded, vesionid:{0}", obj.VersionId);
}
catch (Exception ex)
{
    Console.WriteLine("Get object failed. {0}", ex.Message);
}