Todos os produtos
Search
Central de documentação

Object Storage Service:Image processing (iOS SDK)

Última atualização: Aug 27, 2026

O Image Processing (IMG) do Object Storage Service (OSS) é um serviço seguro, econômico e altamente confiável para processar grandes volumes de imagens. Após enviar as imagens para o OSS, chame operações da API RESTful para processá-las em qualquer dispositivo conectado à internet, a qualquer momento e lugar.

Uso

Acesse o IMG por meio de solicitações HTTP GET padrão. Configure os parâmetros do IMG na query string da URL do objeto de imagem.

Se a lista de controle de acesso (ACL) de um objeto de imagem for privada, apenas usuários autorizados poderão acessá-lo.

  • Acesso anônimo

    OSSTask * task = [client presignPublicURLWithBucketName:@"examplebucket"
                                              withObjectKey:@"exampledir/example.jpg"
                                             withParameters:@{@"x-oss-process": @"image/resize,w_50"}];
    [task continueWithBlock:^id(OSSTask *task) {
        if (!task.error) {
            NSLog(@"download image success!");
            OSSGetObjectResult * getResult = task.result;
            NSLog(@"download image data: %@", getResult.downloadedData);
        } else {
            NSLog(@"download object failed, error: %@" ,task.error);
        }
        return nil;
    }];
    // [task waitUntilFinished];
  • Acesso autorizado

    Ao usar o SDK para processar uma imagem, defina os parâmetros do IMG na propriedade request.xOssProcess ao baixar a imagem. Exemplo:

    OSSGetObjectRequest * request = [OSSGetObjectRequest new];
    // Specify the name of the bucket in which the image is stored. 
    request.bucketName = @"examplebucket";
    // Specify the name of the image. If the image is not stored in the root directory of the bucket, you must specify the full path of the image. Example: exampledir/example.jpg.    
    request.objectKey = @"exampledir/example.jpg";
    // Specify IMG parameters. 
    request.xOssProcess = @"image/resize,m_lfit,w_100,h_100";
    OSSTask * getTask = [client getObject:request];
    [getTask continueWithBlock:^id(OSSTask *task) {
        if (!task.error) {
            NSLog(@"download image success!");
            OSSGetObjectResult * getResult = task.result;
            NSLog(@"download image data: %@", getResult.downloadedData);
        } else {
            NSLog(@"download object failed, error: %@" ,task.error);
        }
        return nil;
    }];
    // [getTask waitUntilFinished];
    // [request cancel];

Salvar imagens processadas

O exemplo a seguir mostra como salvar imagens processadas:

OSSImagePersistRequest *request = [OSSImagePersistRequest new];
// Specify the name of the bucket in which the source image is stored. 
request.fromBucket = @"srcbucket";
// Specify the name of the source image. If the image is not stored in the root directory of the bucket, you must specify the full path of the image. Example: exampledir/src.jpg. 
request.fromObject = @"exampledir/src.jpg";
// Specify the name of the bucket that stores the processed image. The bucket must be located in the same region as the bucket in which the source image is stored. 
request.toBucket = @"destbucket";
// Specify the name of the processed image.
request.toObject = @"exampledir/dest.jpg";
// Proportionally resize the image to a width of 100 pixels and save the processed image to the specified bucket. 
request.action = @"image/resize,w_100";
// request.action = @"resize,w_100";
OSSTask * getTask = [client imageActionPersist:request];

[getTask continueWithBlock:^id _Nullable(OSSTask * _Nonnull task) {
    return nil;
}];
// [getTask waitUntilFinished];

Gerar uma URL de objeto assinada com parâmetros do IMG

As URLs de objetos privados exigem assinatura. Não adicione parâmetros do IMG diretamente ao final de uma URL assinada. Para processar um objeto de imagem privado, inclua os parâmetros do IMG na assinatura.

O exemplo a seguir mostra como gerar uma URL assinada com parâmetros do IMG:

// Specify the name of the bucket in which the image is stored. 
NSString *bucketName = @"examplebucket";
// Specify the name of the image. If the image is not stored in the root directory of the bucket, you must specify the full path of the image. Example: exampledir/example.jpg. 
NSString *objectKey = @"exampledir/example.jpg";
// Generate a signed URL that includes IMG parameters. Set the validity period of the signed URL to 1,800 seconds. 
OSSTask *task = [_client presignConstrainURLWithBucketName:bucketName withObjectKey:objectKey withExpirationInterval:30 * 60 withParameters:@{@"x-oss-process": @"image/resize,w_50"}];
NSLog(@"url: %@", task.result);

Referências

Para obter mais informações sobre os parâmetros do IMG compatíveis, consulte IMG parameters.