Todos os produtos
Search
Central de documentação

Object Storage Service:Upload callbacks (iOS SDK)

Última atualização: Sep 22, 2026

Este tópico descreve como configurar callback de upload.

Notas

  • Antes de executar o código de exemplo deste tópico, crie uma instância do OSSClient por meio de métodos como o uso de um nome de domínio personalizado ou do Security Token Service (STS). Para mais detalhes, consulte Inicialização (iOS SDK).

    Nota

    Especifique o endpoint na inicialização para definir a região do bucket.

  • Para fazer upload de um objeto, sua conta precisa da permissão oss:PutObject. Para obter mais informações, consulte Anexar uma política personalizada a um usuário do RAM.

Exemplos

O trecho de código a seguir demonstra como configurar um callback de upload:

OSSPutObjectRequest * request = [OSSPutObjectRequest new];
// Specify the name of the bucket. Example: examplebucket. 
request.bucketName = @"examplebucket";
// Specify the full path of the object. Do not include the bucket name in the full path. Example: exampledir/exampleobject.txt. 
request.objectKey = @"exampledir/exampleobject.txt";
request.uploadingFileURL = [NSURL fileURLWithPath:@"<filepath>"];
// Configure callback parameters.
request.callbackParam = @{
                          @"callbackUrl": @"<your server callback address>",
                          @"callbackBody": @"<your callback body>"
                          };
// Specify custom variables. 
request.callbackVar = @{
                        @"<var1>": @"<value1>",
                        @"<var2>": @"<value2>"
                        };
request.uploadProgress = ^(int64_t bytesSent, int64_t totalByteSent, int64_t totalBytesExpectedToSend) {
    NSLog(@"%lld, %lld, %lld", bytesSent, totalByteSent, totalBytesExpectedToSend);
};
OSSTask * task = [client putObject:request];
[task continueWithBlock:^id(OSSTask *task) {
    if (task.error) {
        OSSLogError(@"%@", task.error);
    } else {
        OSSPutObjectResult * result = task.result;
        NSLog(@"Result - requestId: %@, headerFields: %@, servercallback: %@",
              result.requestId,
              result.httpResponseHeaderFields,
              result.serverReturnJsonString);
    }
    return nil;
}];
// Implement synchronous blocking to wait for the task to complete. 
// [task waitUntilFinished]; 

Referências

  • Acesse o GitHub para consultar o código de exemplo completo utilizado para configurar callback de upload.

  • Consulte Callback para obter detalhes sobre as operações de API disponíveis para configurar callback de upload.