All Products
Search
Document Center

Object Storage Service:Synchronous processing (OSS SDK for Python V2)

Last Updated:Mar 20, 2026

Use process_object() to apply image or document processing operations to an OSS object and save the result to a destination bucket — all in a single synchronous call.

Usage notes

  • The sample code uses the China (Hangzhou) region (cn-hangzhou) with the public endpoint. If you access OSS from another Alibaba Cloud service in the same region, use the internal endpoint. For region-to-endpoint mappings, see Regions and endpoints.

Method definition

process_object(request: ProcessObjectRequest, **kwargs) → ProcessObjectResult

Request parameters

ParameterTypeDescription
requestProcessObjectRequestThe request object. See ProcessObjectRequest.

Response

TypeDescription
ProcessObjectResultThe result object. See ProcessObjectResult.

For the complete method definition, see process_object.

How it works

The process parameter passed to process_object() is a string that combines a style (the processing instruction) with an optional save-as directive:

{style}|sys/saveas,o_{base64_key},b_{base64_bucket}
ComponentExampleDescription
{style}image/resize,m_fixed,w_100,h_100The processing instruction, such as an image resize or blind watermark
sys/saveassys/saveasSaves the processed result to a specified object
o_{base64_key}o_<Base64-encoded object name>The destination object name, Base64-encoded for URL safety
b_{base64_bucket}b_<Base64-encoded bucket name>The destination bucket name, Base64-encoded for URL safety

Both the destination bucket name and object name must be Base64-encoded using base64.b64encode(...).decode().

Sample code

The following example resizes an image and saves the result to a destination bucket:

import base64
import argparse
import alibabacloud_oss_v2 as oss

parser = argparse.ArgumentParser(description="process object sample")
parser.add_argument('--region', help='The region in which the bucket is located.', required=True)
parser.add_argument('--bucket', help='The name of the bucket.', required=True)
parser.add_argument('--endpoint', help='The domain names that other services can use to access OSS')
parser.add_argument('--key', help='The name of the object.', required=True)
parser.add_argument('--style', help='The style to apply for processing the object, such as image resizing.', required=True)
parser.add_argument('--target_image', help='Specify the name of the processed image.', required=True)
parser.add_argument('--target_bucket', help='Specify the name of the bucket used to store processed images.', required=True)

def main():
    args = parser.parse_args()

    # Load access credentials from environment variables.
    credentials_provider = oss.credentials.EnvironmentVariableCredentialsProvider()

    cfg = oss.config.load_default()
    cfg.credentials_provider = credentials_provider
    cfg.region = args.region

    if args.endpoint is not None:
        cfg.endpoint = args.endpoint

    client = oss.Client(cfg)

    # Build the processing instruction.
    # Example style: image/resize,m_fixed,w_100,h_100
    style = args.style

    # Base64-encode the destination bucket and object names for URL safety.
    target_bucket_base64 = base64.b64encode(args.target_bucket.encode()).decode()
    target_key_base64 = base64.b64encode(args.target_image.encode()).decode()

    process = f"{style}|sys/saveas,o_{target_key_base64},b_{target_bucket_base64}"

    result = client.process_object(oss.ProcessObjectRequest(
        bucket=args.bucket,   # Source bucket name
        key=args.key,         # Source object name
        process=process,      # Processing instruction
    ))

    print(f'status code: {result.status_code},'
          f' request id: {result.request_id},'
          f' bucket: {result.bucket},'
          f' file size: {result.file_size},'
          f' key: {result.key},'
          f' process status: {result.process_status},'
          )

if __name__ == "__main__":
    main()

Result fields

FieldDescription
status_codeHTTP status code of the response.
process_statusThe processing result status.
request_idThe unique request ID. Include this when reporting issues.
bucketThe bucket where the processed object is saved.
keyThe destination object name.
file_sizeThe size of the processed object.

Common scenarios

All examples below show only the key lines that differ from the sample code above. Use the same client initialization and sys/saveas pattern.

Add a blind watermark to an image

A blind watermark embeds invisible text into an image. The watermark content must be URL-safe Base64-encoded:

import base64

# Encode the watermark text using URL-safe Base64.
content = "Copyrighted by Alibaba Cloud"
encoded_content = base64.urlsafe_b64encode(content.encode()).decode()

style = f"image/blindwatermark,content_{encoded_content}"

# Base64-encode the destination bucket and object names (standard encoding).
target_bucket_base64 = base64.b64encode(args.target_bucket.encode()).decode()
target_key_base64 = base64.b64encode(args.target_image.encode()).decode()

process = f"{style}|sys/saveas,o_{target_key_base64},b_{target_bucket_base64}"

result = client.process_object(oss.ProcessObjectRequest(
    bucket=args.bucket,
    key=args.key,
    process=process,
))
The blind watermark content uses URL-safe Base64 encoding (base64.urlsafe_b64encode), while bucket and object names use standard Base64 encoding (base64.b64encode).

For a complete runnable example, see process_object.py.

What's next