Tous les produits
Search
Centre de documentation

Object Storage Service:Barre de progression (SDK iOS)

Dernière mise à jour :Aug 18, 2026

Utilisez une barre de progression pour suivre l'avancement du téléversement ou du téléchargement d'un objet. L'exemple ci-dessous s'appuie sur l'opération PutObject pour illustrer l'affichage de la barre de progression lors du téléversement d'un objet.

Notes

  • Avant d'exécuter l'exemple de code de cette rubrique, créez une instance OSSClient, par exemple en utilisant un nom de domaine personnalisé ou le Security Token Service (STS). Pour plus d'informations, consultez la section Initialisation.

    Remarque

    La région du bucket correspond à celle de l'endpoint spécifié lors de l'initialisation.

  • Pour téléverser un fichier, vous devez disposer de l'autorisation oss:PutObject. Pour plus d'informations, consultez la section Accorder des politiques d'accès personnalisées à un utilisateur RAM.

Exemples

L'exemple de code suivant montre comment afficher la barre de progression lors du téléversement d'un fichier local vers 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]; 

Références

  • Pour consulter le code complet relatif aux barres de progression lors du téléversement d'objets, rendez-vous sur GitHub.

  • Pour plus d'informations sur l'initialisation d'une instance OSSClient, consultez la section Initialisation.