Todos los productos
Search
Centro de documentos

Object Storage Service:Barra de progreso (SDK para iOS)

Última actualización: Sep 22, 2026

La barra de progreso indica el avance de un objeto durante su carga o descarga. En este ejemplo se utiliza la operación PutObject para mostrar cómo visualizar la barra de progreso al cargar un objeto.

Notas

  • Antes de ejecutar el código de ejemplo de este tema, cree una instancia de OSSClient mediante métodos como el uso de un nombre de dominio personalizado o Security Token Service (STS). Para más información, consulte Initialization.

    Nota

    La región del bucket depende de la región del endpoint que se especifique durante la inicialización.

  • Para cargar un archivo, necesita el permiso oss:PutObject. Para más información, consulte Grant custom access policies to a RAM user.

Ejemplos

A continuación se muestra un ejemplo de código para visualizar la barra de progreso cuando se carga un archivo local a un 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]; 

Referencias

  • Para consultar el código de ejemplo completo sobre barras de progreso en la carga de objetos, visite GitHub.

  • Para más información sobre cómo inicializar una instancia de OSSClient, consulte Initialization.