All Products
Search
Document Center

Object Storage Service:Asynchronous processing

Last Updated:Apr 03, 2026

Asynchronous processing (x-oss-async-process) allows a program to execute other tasks without waiting for a task to complete. This topic explains how to use OSS SDK for Go V2 for asynchronous processing in scenarios such as document conversion, video transcoding, and video merging.

Limitations

  • The sample code in this topic uses the China (Hangzhou) region (ID: cn-hangzhou) and a public endpoint by default. If you want to access OSS from other Alibaba Cloud services in the same region, use an internal endpoint. For more information about the regions and endpoints supported by OSS, see OSS regions and endpoints.

  • In this topic, access credentials are obtained from environment variables. For how to configure access credentials, see Configure access credentials.

Method

func (c *Client) AsyncProcessObject(ctx context.Context, request *AsyncProcessObjectRequest, optFns ...func(*Options)) (*AsyncProcessObjectResult, error)

Request parameters

Parameter

Type

Description

ctx

context.Context

The context of the request, which can be used to specify the total duration of the request

request

*AsyncProcessObjectRequest

Specify the request parameters for the specific interface. For more information, see AsyncProcessObjectRequest

optFns

...func(*Options)

(Optional) Interface-level configuration parameters. For more information, see Options

Return value list

Return value name

Type

Description

result

*AsyncProcessObjectResult

The return value of the interface, valid when err is nil. For more information, see AsyncProcessObjectResult

err

error

The status of the request. If the request fails, the value of err is not nil

Sample code

The following code shows how to use the Go SDK V2 for document format conversion to achieve the desired output type.

package main

import (
	"context"
	"encoding/base64"
	"flag"
	"fmt"
	"log"
	"strings"

	"github.com/aliyun/alibabacloud-oss-go-sdk-v2/oss"
	"github.com/aliyun/alibabacloud-oss-go-sdk-v2/oss/credentials"
)

var (
	region     string
	bucketName string 
	objectName string
)

// The init function is called before main to set up the command-line flags.
func init() {
	// Sets a command-line flag for the region.
	flag.StringVar(&region, "region", "", "The region in which the bucket is located.")
	// Sets a command-line flag for the bucket name.
	flag.StringVar(&bucketName, "bucket", "", "The name of the bucket.")
	// Sets a command-line flag for the name of the document to convert.
	flag.StringVar(&objectName, "object", "", "The name of the object.")
}

func main() {
	flag.Parse() // Parses the command-line flags.

	// Verifies that the region is provided. If not, prints default flags and exits.
	if len(region) == 0 {
		flag.PrintDefaults()
		log.Fatalf("invalid parameters, region required")
	}
	// Verifies that the bucket name is provided. If not, prints default flags and exits.
	if len(bucketName) == 0 {
		flag.PrintDefaults()
		log.Fatalf("invalid parameters, bucket name required")
	}
	// Verifies that the object name is provided. If not, prints default flags and exits.
	if len(objectName) == 0 {
		flag.PrintDefaults()
		log.Fatalf("invalid parameters, object name required")
	}

	// Creates a configuration object that uses environment variables for credentials and the specified region.
	cfg := oss.LoadDefaultConfig().
		WithCredentialsProvider(credentials.NewEnvironmentVariableCredentialsProvider()).
		WithRegion(region)

	client := oss.NewClient(cfg) // Creates a new OSS client using the configuration.

	// Specifies the name of the output file.
	targetKey := "dest.png"

	// Builds the style string for document processing and conversion.
	animationStyle := "doc/convert,target_png,source_docx" // Defines the rule to convert the source .docx document to a .png image.

	// Builds the processing instruction, including the save path and the Base64-encoded bucket name and target object name.
	bucketNameEncoded := strings.TrimRight(base64.URLEncoding.EncodeToString([]byte(bucketName)), "=")
	targetKeyEncoded := strings.TrimRight(base64.URLEncoding.EncodeToString([]byte(targetKey)), "=")
	process := fmt.Sprintf("%s|sys/saveas,b_%v,o_%v/notify", animationStyle, bucketNameEncoded, targetKeyEncoded)

	// Builds an AsyncProcessObjectRequest to initiate an asynchronous processing task.
	request := &oss.AsyncProcessObjectRequest{
		Bucket:       oss.Ptr(bucketName), // Specifies the bucket to operate on.
		Key:          oss.Ptr(objectName), // Specifies the object to process.
		AsyncProcess: oss.Ptr(process),    
	}

	// Executes the request to process the object asynchronously and receive the result.
	result, err := client.AsyncProcessObject(context.TODO(), request)
	if err != nil {
		log.Fatalf("failed to asynchronously process object %v", err)
	}

	log.Printf("async process object result:%#v\n", result)
}

Common scenarios

Video transcoding

Use the video transcoding feature to alter the video encoding format, reduce resolution and bitrate to decrease video file size, and convert the video container format.

package main

import (
	"context"
	"encoding/base64"
	"flag"
	"fmt"
	"log"
	"strings"

	"github.com/aliyun/alibabacloud-oss-go-sdk-v2/oss"
	"github.com/aliyun/alibabacloud-oss-go-sdk-v2/oss/credentials"
)

var (
	region     string // Specify a variable to store the region information obtained from the command line
	bucketName string // Specify a variable to store the bucket name obtained from the command line
	objectName string // Specify a variable to store the object name obtained from the command line
)

func init() {
	// Use a command line parameter to specify the region
	flag.StringVar(&region, "region", "", "The region in which the bucket is located.")
	// Use a command line parameter to specify the bucket name
	flag.StringVar(&bucketName, "bucket", "", "The name of the bucket.")
	// Use a command line parameter to specify the name of the video to be transcoded
	flag.StringVar(&objectName, "object", "", "The name of the object.")
}

func main() {
	flag.Parse() // Parse command line parameters

	// Check whether the region is specified. If the region is not specified, output the default parameters and exit the program
	if len(region) == 0 {
		flag.PrintDefaults()
		log.Fatalf("invalid parameters, region required")
	}
	// Check whether the bucket name is specified. If the bucket name is not specified, output the default parameters and exit the program
	if len(bucketName) == 0 {
		flag.PrintDefaults()
		log.Fatalf("invalid parameters, bucket name required")
	}
	// Check whether the object name is specified. If the object name is not specified, output the default parameters and exit the program
	if len(objectName) == 0 {
		flag.PrintDefaults()
		log.Fatalf("invalid parameters, object name required")
	}

	// Create a configuration object and use environment variables as the credential provider and the specified region
	cfg := oss.LoadDefaultConfig().
		WithCredentialsProvider(credentials.NewEnvironmentVariableCredentialsProvider()).
		WithRegion(region)

	client := oss.NewClient(cfg) // Create a new OSS client using the configuration

	// Specify the name of the output video
	targetObject := "dest.avi"

	// Define the processing style. This is a sample video conversion configuration, including format, video codec, resolution, bitrate, frame rate, audio codec, audio bitrate, and other parameters
	style := "video/convert,f_avi,vcodec_h265,s_1920x1080,vb_2000000,fps_30,acodec_aac,ab_100000,sn_1"

	// Construct an asynchronous processing instruction, including the processing style and the save location of the processed file (the bucket name and object name are Base64-encoded)
	process := fmt.Sprintf("%s|sys/saveas,b_%v,o_%v",
		style,
		strings.TrimRight(base64.URLEncoding.EncodeToString([]byte(bucketName)), "="),   // Base64-encode the bucket name and remove the trailing '='
		strings.TrimRight(base64.URLEncoding.EncodeToString([]byte(targetObject)), "=")) // Base64-encode the object name and remove the trailing '='

	// Create an AsyncProcessObject request to initiate asynchronous processing of a specific object
	request := &oss.AsyncProcessObjectRequest{
		Bucket:       oss.Ptr(bucketName), // Specify the name of the bucket to operate
		Key:          oss.Ptr(objectName), // Specify the name of the video to process
		AsyncProcess: oss.Ptr(process),
	}

	// Execute the request to asynchronously process the object and receive the return result
	result, err := client.AsyncProcessObject(context.TODO(), request)
	if err != nil {
		log.Fatalf("failed to async process object %v", err)
	}

	log.Printf("async process object result:%#v\n", result)
}

Video-to-animated-image conversion

Convert videos to animated images in GIF or WebP format using video-to-animated-image conversion.

package main

import (
	"context"
	"encoding/base64"
	"flag"
	"fmt"
	"log"
	"strings"

	"github.com/aliyun/alibabacloud-oss-go-sdk-v2/oss"
	"github.com/aliyun/alibabacloud-oss-go-sdk-v2/oss/credentials"
)

var (
	region     string // Stores the region obtained from the command line.
	bucketName string // Stores the bucket name obtained from the command line.
	objectName string // Stores the object name obtained from the command line.
)

// The init function is called before main to set up the command-line flags.
func init() {
	// Sets a command-line flag for the region.
	flag.StringVar(&region, "region", "", "The region in which the bucket is located.")
	// Sets a command-line flag for the bucket name.
	flag.StringVar(&bucketName, "bucket", "", "The name of the bucket.")
	// Sets a command-line flag for the name of the video to process.
	flag.StringVar(&objectName, "object", "", "The name of the object.")
}

func main() {
	flag.Parse() // Parses the command-line flags.

	// Verifies that the region is provided. If not, prints default flags and exits.
	if len(region) == 0 {
		flag.PrintDefaults()
		log.Fatalf("invalid parameters, region required")
	}
	// Verifies that the bucket name is provided. If not, prints default flags and exits.
	if len(bucketName) == 0 {
		flag.PrintDefaults()
		log.Fatalf("invalid parameters, bucket name required")
	}
	// Verifies that the object name is provided. If not, prints default flags and exits.
	if len(objectName) == 0 {
		flag.PrintDefaults()
		log.Fatalf("invalid parameters, object name required")
	}

	// Creates a configuration object that uses environment variables for credentials and the specified region.
	cfg := oss.LoadDefaultConfig().
		WithCredentialsProvider(credentials.NewEnvironmentVariableCredentialsProvider()).
		WithRegion(region)

	client := oss.NewClient(cfg) // Creates a new OSS client using the configuration.

	// Specifies the name of the output GIF file.
	targetKey := "destexample.gif"

	// Defines parameters for video-to-GIF conversion, including width, height, and frame interval.
	animationStyle := "video/animation,f_gif,w_100,h_100,inter_1000"

	// Builds the processing instruction, including the save path and the Base64-encoded bucket and target object names.
	bucketNameEncoded := strings.TrimRight(base64.URLEncoding.EncodeToString([]byte(bucketName)), "=")
	targetKeyEncoded := strings.TrimRight(base64.URLEncoding.EncodeToString([]byte(targetKey)), "=")
	process := fmt.Sprintf("%s|sys/saveas,b_%v,o_%v/notify,topic_QXVkaW9Db252ZXJ0", animationStyle, bucketNameEncoded, targetKeyEncoded)

	// Builds an AsyncProcessObjectRequest to initiate an asynchronous processing task.
	request := &oss.AsyncProcessObjectRequest{
		Bucket:       oss.Ptr(bucketName), // Specifies the bucket to operate on.
		Key:          oss.Ptr(objectName), // Specifies the video to process.
		AsyncProcess: oss.Ptr(process),    
	}

	// Executes the request to process the object asynchronously and receive the result.
	result, err := client.AsyncProcessObject(context.TODO(), request)
	if err != nil {
		log.Fatalf("failed to asynchronously process object %v", err)
	}

	log.Printf("async process object result:%#v\n", result)
}

Video sprite capture

Capture video frames and stitch them into a sprite using the video sprite capture feature based on specific rules.

package main

import (
	"context"
	"encoding/base64"
	"flag"
	"fmt"
	"log"
	"strings"

	"github.com/aliyun/alibabacloud-oss-go-sdk-v2/oss"
	"github.com/aliyun/alibabacloud-oss-go-sdk-v2/oss/credentials"
)

var (
	region     string // Stores the region obtained from the command line.
	bucketName string // Stores the bucket name obtained from the command line.
	objectName string // Stores the object name obtained from the command line.
)

// The init function is called before main to set up the command-line flags.
func init() {
	// Sets a command-line flag for the region.
	flag.StringVar(&region, "region", "", "The region in which the bucket is located.")
	// Sets a command-line flag for the bucket name.
	flag.StringVar(&bucketName, "bucket", "", "The name of the bucket.")
	// Sets a command-line flag for the name of the video to process.
	flag.StringVar(&objectName, "object", "", "The name of the object.")
}

func main() {
	flag.Parse() // Parses the command-line flags.

	// Verifies that the region is provided. If not, prints default flags and exits.
	if len(region) == 0 {
		flag.PrintDefaults()
		log.Fatalf("invalid parameters, region required")
	}
	// Verifies that the bucket name is provided. If not, prints default flags and exits.
	if len(bucketName) == 0 {
		flag.PrintDefaults()
		log.Fatalf("invalid parameters, bucket name required")
	}
	// Verifies that the object name is provided. If not, prints default flags and exits.
	if len(objectName) == 0 {
		flag.PrintDefaults()
		log.Fatalf("invalid parameters, object name required")
	}

	// Creates a configuration object that uses environment variables for credentials and the specified region.
	cfg := oss.LoadDefaultConfig().
		WithCredentialsProvider(credentials.NewEnvironmentVariableCredentialsProvider()).
		WithRegion(region)

	client := oss.NewClient(cfg) // Creates a new OSS client using the configuration.

	// Specifies the name of the output sprite file.
	targetKey := "example.jpg"

	// Builds the parameters for video sprite capture.
	animationStyle := "video/sprite,f_jpg,sw_100,sh_100,inter_10000,tw_10,th_10,pad_0,margin_0"

	// Builds the processing instruction, including the save path and the Base64-encoded bucket and target object names.
	bucketNameEncoded := strings.TrimRight(base64.URLEncoding.EncodeToString([]byte(bucketName)), "=")
	targetKeyEncoded := strings.TrimRight(base64.URLEncoding.EncodeToString([]byte(targetKey)), "=")
	process := fmt.Sprintf("%s|sys/saveas,b_%v,o_%v/notify,topic_QXVkaW9Db252ZXJ0", animationStyle, bucketNameEncoded, targetKeyEncoded)

	// Builds an AsyncProcessObjectRequest to initiate an asynchronous processing task.
	request := &oss.AsyncProcessObjectRequest{
		Bucket:       oss.Ptr(bucketName), // Specifies the bucket to operate on.
		Key:          oss.Ptr(objectName), // Specifies the object to process.
		AsyncProcess: oss.Ptr(process),    
	}

	// Executes the request to process the object asynchronously and receive the result.
	result, err := client.AsyncProcessObject(context.TODO(), request)
	if err != nil {
		log.Fatalf("failed to asynchronously process object %v", err)
	}

	log.Printf("async process object result:%#v\n", result)
}

Frame capture

Capture video frames as needed and convert them to a specific format with frame capture.

package main

import (
	"context"
	"encoding/base64"
	"flag"
	"fmt"
	"log"
	"strings"

	"github.com/aliyun/alibabacloud-oss-go-sdk-v2/oss"
	"github.com/aliyun/alibabacloud-oss-go-sdk-v2/oss/credentials"
)

var (
	region     string // Stores the region obtained from the command line.
	bucketName string // Stores the bucket name obtained from the command line.
	objectName string // Stores the object name obtained from the command line.
)

// The init function is called before main to set up the command-line flags.
func init() {
	// Sets a command-line flag for the region.
	flag.StringVar(&region, "region", "", "The region in which the bucket is located.")
	// Sets a command-line flag for the bucket name.
	flag.StringVar(&bucketName, "bucket", "", "The name of the bucket.")
	// Sets a command-line flag for the name of the video to process.
	flag.StringVar(&objectName, "object", "", "The name of the object.")
}

func main() {
	flag.Parse() // Parses the command-line flags.

	// Verifies that the region is provided. If not, prints default flags and exits.
	if len(region) == 0 {
		flag.PrintDefaults()
		log.Fatalf("invalid parameters, region required")
	}
	// Verifies that the bucket name is provided. If not, prints default flags and exits.
	if len(bucketName) == 0 {
		flag.PrintDefaults()
		log.Fatalf("invalid parameters, bucket name required")
	}
	// Verifies that the object name is provided. If not, prints default flags and exits.
	if len(objectName) == 0 {
		flag.PrintDefaults()
		log.Fatalf("invalid parameters, object name required")
	}

	// Creates a configuration object that uses environment variables for credentials and the specified region.
	cfg := oss.LoadDefaultConfig().
		WithCredentialsProvider(credentials.NewEnvironmentVariableCredentialsProvider()).
		WithRegion(region)

	client := oss.NewClient(cfg) // Creates a new OSS client using the configuration.

	// Specifies the name of the output file after frame capture.
	targetKey := "dest.png"

	// Builds the parameters for frame capture.
	animationStyle := "video/snapshots,f_jpg,w_100,h_100,scaletype_crop,inter_10000"

	// Builds the processing instruction, including the save path and the Base64-encoded bucket and target object names.
	bucketNameEncoded := strings.TrimRight(base64.URLEncoding.EncodeToString([]byte(bucketName)), "=")
	targetKeyEncoded := strings.TrimRight(base64.URLEncoding.EncodeToString([]byte(targetKey)), "=")
	process := fmt.Sprintf("%s|sys/saveas,b_%v,o_%v/notify,topic_QXVkaW9Db252ZXJ0", animationStyle, bucketNameEncoded, targetKeyEncoded)

	// Builds an AsyncProcessObjectRequest to initiate an asynchronous processing task.
	request := &oss.AsyncProcessObjectRequest{
		Bucket:       oss.Ptr(bucketName), // Specifies the bucket to operate on.
		Key:          oss.Ptr(objectName), // Specifies the object to process.
		AsyncProcess: oss.Ptr(process),    
	}

	// Executes the request to process the object asynchronously and receive the result.
	result, err := client.AsyncProcessObject(context.TODO(), request)
	if err != nil {
		log.Fatalf("failed to asynchronously process object %v", err)
	}

	log.Printf("async process object result:%#v\n", result)
}

Video merging

Merge multiple videos into a single video file in the specified format using the video merging feature.

package main

import (
	"context"
	"encoding/base64"
	"flag"
	"fmt"
	"log"
	"strings"

	"github.com/aliyun/alibabacloud-oss-go-sdk-v2/oss"
	"github.com/aliyun/alibabacloud-oss-go-sdk-v2/oss/credentials"
)

var (
	region     string // Specify a variable to store the region information obtained from the command line
	bucketName string // Specify a variable to store the bucket name obtained from the command line
)

// The init function is executed before the main function to initialize the program
func init() {
	// Use a command line parameter to specify the region
	flag.StringVar(&region, "region", "", "The region in which the bucket is located.")
	// Use a command line parameter to specify the bucket name
	flag.StringVar(&bucketName, "bucket", "", "The name of the bucket.")
}

func main() {
	flag.Parse() // Parse command line parameters

	// Check whether the region is specified. If the region is not specified, output the default parameters and exit the program
	if len(region) == 0 {
		flag.PrintDefaults()
		log.Fatalf("invalid parameters, region required")
	}
	// Check whether the bucket name is specified. If the bucket name is not specified, output the default parameters and exit the program
	if len(bucketName) == 0 {
		flag.PrintDefaults()
		log.Fatalf("invalid parameters, bucket name required")
	}

	// Create a configuration object and use environment variables as the credential provider and the specified region
	cfg := oss.LoadDefaultConfig().
		WithCredentialsProvider(credentials.NewEnvironmentVariableCredentialsProvider()).
		WithRegion(region)

	client := oss.NewClient(cfg) // Create a new OSS client using the configuration

	// Specify the name of the output video file
	targetObject := "dest.mp4"
	// Specify the names of the video files to be merged
	video1 := "concat1.mp4"
	video2 := "concat2.mp4"

	// Create a style variable of the string type to store video merging parameters
	style := fmt.Sprintf("video/concat,ss_0,f_mp4,vcodec_h264,fps_25,vb_1000000,acodec_aac,ab_96000,ar_48000,ac_2,align_1/pre,o_%s/sur,o_%s,t_0", strings.TrimRight(base64.URLEncoding.EncodeToString([]byte(video1)), "="), strings.TrimRight(base64.URLEncoding.EncodeToString([]byte(video2)), "="))
	// Create an asynchronous processing instruction
	process := fmt.Sprintf("%s|sys/saveas,b_%v,o_%v/notify,topic_QXVkaW9Db252ZXJ0", style, strings.TrimRight(base64.URLEncoding.EncodeToString([]byte(bucketName)), "="), strings.TrimRight(base64.URLEncoding.EncodeToString([]byte(targetObject)), "="))

	// Create an AsyncProcessObject request to initiate asynchronous processing of a specific object
	request := &oss.AsyncProcessObjectRequest{
		Bucket:       oss.Ptr(bucketName), // Specify the name of the bucket to operate
		AsyncProcess: oss.Ptr(process),    
	}

	// Execute the request to asynchronously process the object and receive the return result
	result, err := client.AsyncProcessObject(context.TODO(), request)
	if err != nil {
		log.Fatalf("failed to async process object %v", err)
	}

	log.Printf("async process object result:%#v\n", result)
}

Audio transcoding

Convert audio files from one format to another with audio transcoding.

package main

import (
	"context"
	"encoding/base64"
	"flag"
	"fmt"
	"log"
	"strings"

	"github.com/aliyun/alibabacloud-oss-go-sdk-v2/oss"
	"github.com/aliyun/alibabacloud-oss-go-sdk-v2/oss/credentials"
)

var (
	region     string // Stores the region obtained from the command line.
	bucketName string // Stores the bucket name obtained from the command line.
	objectName string // Stores the object name obtained from the command line.
)

// The init function is called before main to set up the command-line flags.
func init() {
	// Sets a command-line flag for the region.
	flag.StringVar(&region, "region", "", "The region in which the bucket is located.")
	// Sets a command-line flag for the bucket name.
	flag.StringVar(&bucketName, "bucket", "", "The name of the bucket.")
	// Sets a command-line flag for the name of the audio to process.
	flag.StringVar(&objectName, "object", "", "The name of the object.")
}

func main() {
	flag.Parse() // Parses the command-line flags.

	// Verifies that the region is provided. If not, prints default flags and exits.
	if len(region) == 0 {
		flag.PrintDefaults()
		log.Fatalf("invalid parameters, region required")
	}
	// Verifies that the bucket name is provided. If not, prints default flags and exits.
	if len(bucketName) == 0 {
		flag.PrintDefaults()
		log.Fatalf("invalid parameters, bucket name required")
	}
	// Verifies that the object name is provided. If not, prints default flags and exits.
	if len(objectName) == 0 {
		flag.PrintDefaults()
		log.Fatalf("invalid parameters, object name required")
	}

	// Creates a configuration object that uses environment variables for credentials and the specified region.
	cfg := oss.LoadDefaultConfig().
		WithCredentialsProvider(credentials.NewEnvironmentVariableCredentialsProvider()).
		WithRegion(region)

	client := oss.NewClient(cfg) // Creates a new OSS client using the configuration.

	// Specifies the name of the transcoded audio file.
	targetKey := "dest.aac"

	// Builds the style string and parameters for audio transcoding.
	animationStyle := "audio/convert,ss_10000,t_60000,f_aac,ab_96000"

	// Builds the processing instruction, including the save path and the Base64-encoded bucket and target object names.
	bucketNameEncoded := strings.TrimRight(base64.URLEncoding.EncodeToString([]byte(bucketName)), "=")
	targetKeyEncoded := strings.TrimRight(base64.URLEncoding.EncodeToString([]byte(targetKey)), "=")
	process := fmt.Sprintf("%s|sys/saveas,b_%v,o_%v/notify,topic_QXVkaW9Db252ZXJ0", animationStyle, bucketNameEncoded, targetKeyEncoded)

	// Builds an AsyncProcessObjectRequest to initiate an asynchronous processing task.
	request := &oss.AsyncProcessObjectRequest{
		Bucket:       oss.Ptr(bucketName), // Specifies the bucket to operate on.
		Key:          oss.Ptr(objectName), // Specifies the audio file to process.
		AsyncProcess: oss.Ptr(process),    
	}

	// Executes the request to process the object asynchronously and receive the result.
	result, err := client.AsyncProcessObject(context.TODO(), request)
	if err != nil {
		log.Fatalf("failed to asynchronously process object %v", err)
	}

	log.Printf("async process object result:%#v\n", result)
}

Audio merging

Merge multiple audio objects into a single audio object in the specified format with audio merging.

package main

import (
	"context"
	"encoding/base64"
	"flag"
	"fmt"
	"log"
	"strings"

	"github.com/aliyun/alibabacloud-oss-go-sdk-v2/oss"
	"github.com/aliyun/alibabacloud-oss-go-sdk-v2/oss/credentials"
)

var (
	region     string // Stores the region obtained from the command line.
	bucketName string // Stores the bucket name obtained from the command line.
)

// The init function is called before main to set up the command-line flags.
func init() {
	// Sets a command-line flag for the region.
	flag.StringVar(&region, "region", "", "The region in which the bucket is located.")
	// Sets a command-line flag for the bucket name.
	flag.StringVar(&bucketName, "bucket", "", "The name of the bucket.")
}

func main() {
	flag.Parse() // Parses the command-line flags.

	// Verifies that the region is provided. If not, prints default flags and exits.
	if len(region) == 0 {
		flag.PrintDefaults()
		log.Fatalf("invalid parameters, region required")
	}
	// Verifies that the bucket name is provided. If not, prints default flags and exits.
	if len(bucketName) == 0 {
		flag.PrintDefaults()
		log.Fatalf("invalid parameters, bucket name required")
	}

	// Creates a configuration object that uses environment variables for credentials and the specified region.
	cfg := oss.LoadDefaultConfig().
		WithCredentialsProvider(credentials.NewEnvironmentVariableCredentialsProvider()).
		WithRegion(region)

	client := oss.NewClient(cfg) // Creates a new OSS client using the configuration.

	// Specifies the audio files to merge.
	audio1 := "src1.mp3"
	audio2 := "src2.mp3"
	// Specifies the name of the merged audio file.
	targetAudio := "dest.aac"

	// Builds the style string and parameters for audio merging.
	audio1Encoded := strings.TrimRight(base64.URLEncoding.EncodeToString([]byte(audio1)), "=")
	audio2Encoded := strings.TrimRight(base64.URLEncoding.EncodeToString([]byte(audio2)), "=")
	style := fmt.Sprintf("audio/concat,f_aac,ac_1,ar_44100,ab_96000,align_2/pre,o_%s/pre,o_%s,t_0", audio1Encoded, audio2Encoded)

	// Builds the asynchronous processing instruction.
	bucketEncoded := strings.TrimRight(base64.URLEncoding.EncodeToString([]byte(bucketName)), "=")
	targetEncoded := strings.TrimRight(base64.URLEncoding.EncodeToString([]byte(targetAudio)), "=")
	process := fmt.Sprintf("%s|sys/saveas,b_%s,o_%s/notify,topic_QXVkaW9Db252ZXJ0", style, bucketEncoded, targetEncoded)

	// Builds an AsyncProcessObjectRequest to initiate an asynchronous processing task.
	request := &oss.AsyncProcessObjectRequest{
		Bucket:       oss.Ptr(bucketName), // Specifies the bucket to operate on.
		AsyncProcess: oss.Ptr(process),    
	}

	// Executes the request to process the object asynchronously and receive the result.
	result, err := client.AsyncProcessObject(context.TODO(), request)
	if err != nil {
		log.Fatalf("failed to asynchronously process object %v", err)
	}

	log.Printf("async process object result:%#v\n", result)
}

Parse image blind watermark

The code below demonstrates how to parse a blind watermark in an image.

package main

import (
	"context"
	"encoding/base64"
	"flag"
	"fmt"
	"log"
	"strings"

	"github.com/aliyun/alibabacloud-oss-go-sdk-v2/oss"
	"github.com/aliyun/alibabacloud-oss-go-sdk-v2/oss/credentials"
)

var (
	region     string
	bucketName string
	objectName string
)

// The init function is executed before the main function to initialize the program
func init() {
	// Use a command line parameter to specify the region
	flag.StringVar(&region, "region", "", "The region in which the bucket is located.")
	// Use a command line parameter to specify the bucket name
	flag.StringVar(&bucketName, "bucket", "", "The name of the bucket.")
	// Use a command line parameter to specify the name of the image to be processed
	flag.StringVar(&objectName, "object", "", "The name of the object.")
}

func main() {
	flag.Parse() // Parse command line parameters

	// Check whether the region is specified. If the region is not specified, output the default parameters and exit the program
	if len(region) == 0 {
		flag.PrintDefaults()
		log.Fatalf("invalid parameters, region required")
	}
	// Check whether the bucket name is specified. If the bucket name is not specified, output the default parameters and exit the program
	if len(bucketName) == 0 {
		flag.PrintDefaults()
		log.Fatalf("invalid parameters, bucket name required")
	}
	// Check whether the object name is specified. If the object name is not specified, output the default parameters and exit the program
	if len(objectName) == 0 {
		flag.PrintDefaults()
		log.Fatalf("invalid parameters, object name required")
	}

	// Create a configuration object and use environment variables as the credential provider and the specified region
	cfg := oss.LoadDefaultConfig().
		WithCredentialsProvider(credentials.NewEnvironmentVariableCredentialsProvider()).
		WithRegion(region)

	client := oss.NewClient(cfg) // Create a new OSS client using the configuration

	// Specify the name of the watermark image file
	sourceKey := objectName // Specify the name of the image object to process

	// Specify the topic of the MNS message
	topic := "imm-blindwatermark-test"

	// Extract the watermark content from the specified image
	style := "image/deblindwatermark,s_low,t_text"
	encodedTopic := strings.TrimRight(base64.URLEncoding.EncodeToString([]byte(topic)), "=")
	process := fmt.Sprintf("%s|sys/notify,topic_%s", style, encodedTopic)
	// Create an AsyncProcessObject request to initiate asynchronous processing of a specific object
	request := &oss.AsyncProcessObjectRequest{
		Bucket:       oss.Ptr(bucketName), // Specify the name of the bucket to operate
		Key:          oss.Ptr(sourceKey),  // Specify the name of the image to process
		AsyncProcess: oss.Ptr(process),    
	}

	// Execute the request to asynchronously process the object and receive the return result
	result, err := client.AsyncProcessObject(context.TODO(), request)
	if err != nil {
		log.Fatalf("failed to async process object %v", err)
	}

	log.Printf("async process object result:%#v\n", result)
}

References