If you have a large object to download or it is time-consuming to download the entire object at a time, you can use streaming download. Streaming download enables you to download part of the object each time until you have downloaded the entire object.

For the complete code of streaming download, see GitHub.

Run the following code to download a specified OSS object to a stream:

using Aliyun.OSS;
var endpoint = "<yourEndpoint>";
var accessKeyId = "<yourAccessKeyId>";
var accessKeySecret = "<yourAccessKeySecret>";
var bucketName = "<yourBucketName>";
var objectName = "<yourObjectName>";
var downloadFilename = "<yourDownloadFilename>";
// Create an OSSClient instance.
var client = new OssClient(endpoint, accessKeyId, accessKeySecret);
    // Download an object to a stream. OssObject includes object information, such as the bucket that contains the object, object name, metadata, and an input stream.
    var obj = client.GetObject(bucketName, objectName);
    using (var requestStream = obj.Content)
        byte[] buf = new byte[1024];
        var fs = File.Open(downloadFilename, FileMode.OpenOrCreate);
        var len = 0;
        // Use the input stream to read the object content into a file or the memory.
        while ((len = requestStream.Read(buf, 0, 1024)) ! = 0)
            fs.Write(buf, 0, len);
    Console.WriteLine("Get object succeeded");
catch (Exception ex)
    Console.WriteLine("Get object failed. {0}", ex.Message);