All Products
Search
Document Center

Object Storage Service:Range download (iOS SDK)

Last Updated:Nov 29, 2025

If you need only a part of a file, you can use a range download to retrieve a specific portion of the data.

Usage notes

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

Note

The region of the bucket is determined by the region of the endpoint specified during initialization.

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.

Range download is suitable for downloading large objects. If the Range parameter is specified in the request header, the response contains the length of the entire object and the returned data range.

Examples

The following code provides an example of how to perform a range 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";
request.range = [[OSSRange alloc] initWithStart:1 withEnd:99]; // bytes=1-99
// request.range = [[OSSRange alloc] initWithStart:-1 withEnd:99]; // bytes=-99
// request.range = [[OSSRange alloc] initWithStart:10 withEnd:-1]; // bytes=10-
request.downloadProgress = ^(int64_t bytesWritten, int64_t totalBytesWritten, int64_t totalBytesExpectedToWrite) {
    NSLog(@"%lld, %lld, %lld", bytesWritten, totalBytesWritten, totalBytesExpectedToWrite);
};
OSSTask * getTask = [client getObject:request];
[getTask continueWithBlock:^id(OSSTask *task) {
    if (!task.error) {
        NSLog(@"download object success!");
        OSSGetObjectResult * getResult = task.result;
        NSLog(@"download result: %@", getResult.downloadedData);
    } else {
        NSLog(@"download object failed, error: %@" ,task.error);
    }
    return nil;
}];
// [getTask waitUntilFinished];
// [request cancel];

References

  • For more information about the API operation for range downloads, see GetObject.

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