Asynchronous processing (x-oss-async-process) lets your application submit a long-running task — such as converting a Docx file to PNG — and continue executing other work without blocking on the result. Use it when document transformation may take seconds or longer and you cannot afford to hold a thread open waiting.
Prerequisites
Before you begin, make sure you have:
An OSS bucket with the source object already uploaded
OSS_ACCESS_KEY_IDandOSS_ACCESS_KEY_SECRETset as environment variablesThe OSS C# SDK V2 (
AlibabaCloud.OSS.V2) installed in your project
Usage notes
The sample code uses the China (Hangzhou) region (cn-hangzhou) and the public endpoint. To access OSS from another Alibaba Cloud service in the same region, use an internal endpoint instead. For region-to-endpoint mappings, see Regions and endpoints.
Submit an asynchronous document transformation
All examples use AsyncProcessObjectAsync to submit an asynchronous task. The Process string encodes the transformation style, the destination bucket and object key (Base64-encoded), and the /notify suffix that enables asynchronous mode.
Set up the client
using System.Text;
using OSS = AlibabaCloud.OSS.V2; // Alias for the OSS SDK namespace.
var region = "cn-hangzhou"; // The region where the source bucket is located.
var endpoint = null as string; // Optional. Overrides the default endpoint when set.
var bucket = "your bucket name"; // The source bucket name.
var key = "your object key"; // The object key of the document to transform.
// Load default SDK configuration and read credentials from environment variables
// (OSS_ACCESS_KEY_ID and OSS_ACCESS_KEY_SECRET).
var cfg = OSS.Configuration.LoadDefault();
cfg.CredentialsProvider = new OSS.Credentials.EnvironmentVariableCredentialsProvider();
cfg.Region = region;
if (endpoint != null)
{
cfg.Endpoint = endpoint;
}
using var client = new OSS.Client(cfg);Build the processing instruction
// Destination bucket and object key for the transformed output.
var targetBucket = bucket!;
var targetKey = $"process-{key}"; // Add a prefix to distinguish the output object.
// Transformation style: convert a Docx file to PNG.
// Format: doc/convert,target_{output_format},source_{input_format}
var style = "doc/convert,target_png,source_docx";
// Base64-encode the destination bucket name and object key.
var targetBucketBase64 = Convert.ToBase64String(Encoding.UTF8.GetBytes(targetBucket));
var targetKeyBase64 = Convert.ToBase64String(Encoding.UTF8.GetBytes(targetKey));
// Assemble the full processing instruction:
// {style}|sys/saveas,b_{base64_bucket},o_{base64_key}/notify
//
// sys/saveas — saves the result to the specified destination.
// b_... — Base64-encoded destination bucket name.
// o_... — Base64-encoded destination object key.
// /notify — enables asynchronous processing mode.
var process = $"{style}|sys/saveas,b_{targetBucketBase64},o_{targetKeyBase64}/notify";Call the API and handle the response
var result = await client.AsyncProcessObjectAsync(new OSS.Models.AsyncProcessObjectRequest
{
Bucket = bucket,
Key = key,
Process = process
});
Console.WriteLine("AsyncProcessObject done");
Console.WriteLine($"Status code: {result.StatusCode}");
Console.WriteLine($"Request ID: {result.RequestId}");
Console.WriteLine($"Process result: {result.ProcessResult}");
Console.WriteLine("Response headers:");
result.Headers.ToList().ForEach(h => Console.WriteLine($" {h.Key}: {h.Value}"));Response fields
| Field | Description |
|---|---|
StatusCode | HTTP status code of the request |
RequestId | Unique request identifier, useful when contacting Alibaba Cloud support |
ProcessResult | Processing result returned by OSS |
What's next
Asynchronous processing — feature overview and supported operations
AsyncProcessObject.cs — complete sample code on GitHub