All Products
Search
Document Center

Object Storage Service:Progress bar (iOS SDK)

Last Updated:Nov 29, 2025

You can use a progress bar to indicate the progress of an object that is being uploaded or downloaded. The PutObject operation is used in the example to describe how to display the progress bar of an object that is being uploaded.

Usage notes

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

    Note

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

  • To upload a file, you must have the oss:PutObject permission. For more information, see Grant custom access policies to a RAM user.

Examples

The following sample code provides an example on how to display the progress bar when you upload a local file to a bucket:

OSSPutObjectRequest * put = [OSSPutObjectRequest new];
// Specify the name of the bucket. Example: examplebucket. 
put.bucketName = @"examplebucket";
// Specify the full path of the object. Do not include the bucket name in the full path. Example: exampledir/exampleobject.txt. 
put.objectKey = @"exampledir/exampleobject.txt";
// Specify the full path of the local file that you want to upload. 
// By default, if you do not specify the full path of the local file, the local file is uploaded from the path of the project to which the sample program belongs. 
put.uploadingFileURL = [NSURL fileURLWithPath:@"filePath"];
// Configure the progress callback function to display the progress bar. 
put.uploadProgress = ^(int64_t bytesSent, int64_t totalByteSent, int64_t totalBytesExpectedToSend) {
    // Specify the number of bytes that are being uploaded, the total number of bytes that are uploaded, and the total number of bytes that you want to upload. 
    NSLog(@"%lld, %lld, %lld", bytesSent, totalByteSent, totalBytesExpectedToSend);
};
OSSTask * putTask = [client putObject:put];
[putTask continueWithBlock:^id(OSSTask *task) {
    if (!task.error) {
        NSLog(@"upload object success!");
    } else {
        NSLog(@"upload object failed, error: %@" , task.error);
    }
    return nil;
}];
// Implement synchronous blocking to wait for the task to complete. 
// [putTask waitUntilFinished]; 

References

  • For the complete sample code of progress bars in object upload, visit GitHub.

  • For more information about how to initialize an OSSClient instance, see Initialization.