All Products
Search
Document Center

Object Storage Service:Streaming download (iOS SDK)

Last Updated:Nov 29, 2025

If a file is too large or takes too long to download, you can use streaming download. This feature lets you process the file in segments until the download is complete.

Usage notes

  • Before you use the sample code in this topic, you must create an OSSClient instance. You can create an instance using a custom domain name or Security Token Service (STS). For more information, see Initialization (iOS SDK).

    Note

    The region of the bucket depends on the region of the endpoint that you specify during initialization.

  • The Object Storage Service (OSS) SDK for iOS does not provide an API operation for stream-based downloads. Instead, it provides a segmented callback feature similar to the NSURLSession library's didReceiveData function. If you set a segmented callback, the download result does not contain the actual data.

Permissions

By default, an Alibaba Cloud account has full permissions. RAM users or RAM roles under an Alibaba Cloud account do not have any permissions by default. The Alibaba Cloud account or account administrator must grant operation permissions through RAM Policy or Bucket policies.

API

Action

Definition

GetObject

oss:GetObject

Downloads an object.

oss:GetObjectVersion

When downloading an object, if you specify the object version through versionId, this permission is required.

kms:Decrypt

When downloading an object, if the object metadata contains X-Oss-Server-Side-Encryption: KMS, this permission is required.

Sample code

The following code shows how to perform a streaming download:

OSSGetObjectRequest * request = [OSSGetObjectRequest new];
// Specify the bucket name. For example, examplebucket.
request.bucketName = @"examplebucket";
// Specify the full path of the object. Do not include the bucket name. For example, exampledir/exampleobject.txt.
request.objectKey = @"exampledir/exampleobject.txt";
// Set the segmented callback function.
request.onRecieveData = ^(NSData * data) {
    NSLog(@"Recieve data, length: %ld", [data length]);
};
OSSTask * getTask = [client getObject:request];
[getTask continueWithBlock:^id(OSSTask *task) {
    if (!task.error) {
        NSLog(@"download object success!");
    } else {
        NSLog(@"download object failed, error: %@" ,task.error);
    }
    return nil;
}];
// [getTask waitUntilFinished];
// [request cancel];

Related documents

  • For more information about the API operation for streaming download, see GetObject.

  • For more information about initializing an OSSClient instance, see Initialization (iOS SDK).