If you need to download a large object or if the download requires a long period of time to complete, you can perform streaming download to download the object in increments.

OSS SDK for iOS does not provide any streaming download APIs. Instead, it provides the multipart callback feature that is similar to the didRecieveData function in the NSURLSession library. The download result does not contain the actual data if multipart callback is configured.

Examples

The following code provides an example on how to download an object by using streaming download:

OSSGetObjectRequest * request = [OSSGetObjectRequest new];
// Specify the name of the bucket. Example: examplebucket. 
request.bucketName = @"examplebucket";
// Specify the full path of the object. The full path cannot contain the bucket name. Example: exampledir/exampleobject.txt. 
request.objectKey = @"exampledir/exampleobject.txt";
// Configure the multipart 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];

References

For more information about the API operation that you can call to perform streaming download, see GetObject.