All Products
Search
Document Center

AgentBay:OSS

Last Updated:Dec 23, 2025

Description

The Object Storage Service (OSS) module lets you interact with the cloud storage service.

Method

Description

Environment

Linux Computer Use

Windows Computer Use

Browser Use

Mobile Use

Code Space

oss_env_init

Initializes OSS environment variables. Sets the Access Key pair, security token, and region configuration.

Supported

Supported

Not supported

Supported

Supported

oss_upload

Uploads a local file or folder to a specified OSS bucket. The environment must be initialized first.

Supported

Supported

Not supported

Supported

Supported

oss_download

Downloads an object from an OSS bucket to a local path. The environment must be initialized first.

Supported

Supported

Not supported

Supported

Supported

oss_upload_annon

Anonymously uploads a file to a specified URL using an HTTP PUT request.

Supported

Supported

Not supported

Supported

Supported

oss_download_annon

Anonymously downloads a file from a specified URL to a local path.

Supported

Supported

Not supported

Supported

Supported

OSS class

The OSS class provides methods to interact with the cloud storage service.

EnvInit - Initialize the OSS environment

Golang

// Initializes and creates OSS environment variables.
func (o *Oss) EnvInit(accessKeyId, accessKeySecret, securityToken, endpoint, region string) (*EnvInitResult, error)

Parameters:

  • accessKeyId: The Access Key ID for OSS authentication.

  • accessKeySecret: The Access Key secret for OSS authentication.

  • securityToken: The security token for OSS authentication.

  • endpoint: The OSS endpoint. If you do not specify this parameter, the default value is used.

  • region: The OSS region. If you do not specify this parameter, the default value is used.

Return values:

  • *EnvInitResult: An object that contains the initialization result and the request ID.

  • error: The error message if the operation fails.

EnvInitResult struct:

type EnvInitResult struct {
    RequestID string // A unique request identifier for debugging.
    Result    string // The result of the environment initialization operation.
}

Example:

package main

import (
	"fmt"
	"os"

	"github.com/aliyun/wuying-agentbay-sdk/golang/pkg/agentbay"
)

func main() {
	// Initialize the SDK.
	client, err := agentbay.NewAgentBay("your_api_key", nil)
	if err != nil {
		fmt.Printf("Error initializing AgentBay client: %v\n", err)
		os.Exit(1)
	}

	// Initialize the OSS environment.
	result, err := client.Oss.EnvInit(
		"your_access_key_id",
		"your_access_key_secret",
		"your_security_token",
		"oss-cn-hangzhou.aliyuncs.com",
		"cn-hangzhou",
	)
	if err != nil {
		fmt.Printf("Error initializing OSS environment: %v\n", err)
		os.Exit(1)
	}

	fmt.Printf("OSS environment initialized successfully, request ID: %s\n", result.RequestID)
}

Python

def env_init(self, access_key_id: str, access_key_secret: str, securityToken: Optional[str] = None,
             endpoint: Optional[str] = None, region: Optional[str] = None) -> OSSClientResult

Parameters:

  • access_key_id: The Access Key ID for OSS authentication.

  • access_key_secret: The Access Key secret for OSS authentication.

  • securityToken: The security token for OSS authentication. This parameter is optional.

  • endpoint: The OSS endpoint. If you do not specify this parameter, the default value is used.

  • region: The OSS region. If you do not specify this parameter, the default value is used.

Return value:

  • OSSClientResult: A result object that contains the client configuration, request ID, success status, and error message.

OSSClientResult struct:

class OSSClientResult(ApiResponse):
    def __init__(self, request_id: str = "", success: bool = False,
                 client_config: Optional[Dict[str, Any]] = None, error_message: str = "")

Example:

from agentbay import AgentBay

# Initialize the SDK.
agent_bay = AgentBay(api_key="your_api_key")

# Initialize the OSS environment.
result = agent_bay.oss.env_init(
    access_key_id="your_access_key_id",
    access_key_secret="your_access_key_secret",
    securityToken="your_security_token",
    endpoint="oss-cn-hangzhou.aliyuncs.com",
    region="cn-hangzhou"
)

if result.success:
    print(f"OSS environment initialized successfully, request ID: {result.request_id}")
else:
    print(f"Failed to initialize OSS environment: {result.error_message}")

TypeScript

async envInit(
  accessKeyId: string,
  accessKeySecret: string,
  securityToken: string,
  endpoint?: string,
  region?: string
): Promise<string>

Parameters:

  • accessKeyId: The Access Key ID for OSS authentication.

  • accessKeySecret: The Access Key secret for OSS authentication.

  • securityToken: The security token for OSS authentication.

  • endpoint: The OSS endpoint. If you do not specify this parameter, the default value is used.

  • region: The OSS region. If you do not specify this parameter, the default value is used.

Return value:

  • Promise<string>: The result of the environment initialization operation.

Exceptions:

  • APIError: Thrown if the environment initialization fails.

Example:

import { AgentBay } from 'wuying-agentbay-sdk';

// Initialize the SDK.
const agentBay = new AgentBay({ apiKey: 'your_api_key' });

// Initialize the OSS environment.
async function initializeOSS() {
  try {
    const result = await agentBay.oss.envInit(
      'your_access_key_id',
      'your_access_key_secret',
      'your_security_token',
      'oss-cn-hangzhou.aliyuncs.com',
      'cn-hangzhou'
    );
    console.log('OSS environment initialized successfully:', result);
  } catch (error) {
    console.error('Error initializing OSS environment:', error);
  }
}

initializeOSS();

createClient - Create an OSS client

Note

Before you call this method, initialize the OSS environment using env_init.

Golang

// Uploads a local file or folder to OSS.
func (o *Oss) Upload(bucket, object, path string) (*UploadResult, error)

Parameters:

  • bucket: The name of the OSS bucket.

  • object: The object key in OSS.

  • path: The path of the local file or folder.

Return values:

  • *UploadResult: An object that contains the upload URL and the request ID.

  • error: The error message if the operation fails.

UploadResult struct:

type UploadResult struct {
    RequestID string // A unique request identifier for debugging.
    URL       string // The URL of the uploaded file.
}

Example:

package main

import (
	"fmt"
	"os"

	"github.com/aliyun/wuying-agentbay-sdk/golang/pkg/agentbay"
)

func main() {
	// Initialize the SDK.
	client, err := agentbay.NewAgentBay("your_api_key", nil)
	if err != nil {
		fmt.Printf("Error initializing AgentBay client: %v\n", err)
		os.Exit(1)
	}

	// Step 1: Initialize the OSS environment.
	_, err = client.Oss.EnvInit(
		"your_access_key_id",
		"your_access_key_secret",
		"your_security_token",
		"oss-cn-hangzhou.aliyuncs.com",
		"cn-hangzhou",
	)
	if err != nil {
		fmt.Printf("Error initializing OSS environment: %v\n", err)
		os.Exit(1)
	}

	// Step 2: Upload the file to OSS.
	result, err := client.Oss.Upload("my-bucket", "my-object", "/path/to/local/file")
	if err != nil {
		fmt.Printf("Error uploading file: %v\n", err)
		os.Exit(1)
	}

	fmt.Printf("File uploaded successfully, URL: %s, request ID: %s\n", result.URL, result.RequestID)
}

Python

def upload(self, bucket: str, object: str, path: str) -> OSSUploadResult

Parameters:

  • bucket: The name of the OSS bucket.

  • object: The object key in OSS.

  • path: The path of the local file or folder.

Return value:

  • OSSUploadResult: A result object that contains the upload result, request ID, success status, and error message.

OSSUploadResult struct:

class OSSUploadResult(ApiResponse):
    def __init__(self, request_id: str = "", success: bool = False,
                 content: str = "", error_message: str = "")

Example:

from wuying_agentbay_sdk import AgentBay

# Initialize the SDK.
agent_bay = AgentBay(api_key="your_api_key")

# Step 1: Initialize the OSS environment.
agent_bay.oss.env_init(
    access_key_id="your_access_key_id",
    access_key_secret="your_access_key_secret",
    security_token="your_security_token",
    endpoint="oss-cn-hangzhou.aliyuncs.com",
    region="cn-hangzhou"
)

# Step 2: Upload the file.
result = agent_bay.oss.upload("my-bucket", "my-object", "/path/to/local/file")
print("File uploaded successfully:", result)

TypeScript

async createClient(
  accessKeyId: string,
  accessKeySecret: string,
  endpoint?: string,
  region?: string
): Promise<string>

Parameters:

  • accessKeyId: The Access Key ID for OSS authentication.

  • accessKeySecret: The Access Key secret for OSS authentication.

  • endpoint: The OSS endpoint. If you do not specify this parameter, the default value is used.

  • region: The OSS region. If you do not specify this parameter, the default value is used.

Return value:

  • Promise<string>: The result of the client creation operation.

Exception:

  • APIError: Thrown if the client creation fails.

Example:

import { AgentBay } from 'wuying-agentbay-sdk';

// Initialize the SDK.
const agentBay = new AgentBay({ apiKey: 'your_api_key' });

// Create an OSS client.
async function createOSSClient() {
  try {
    const result = await agentBay.oss.createClient(
      'your_access_key_id',
      'your_access_key_secret',
      'oss-cn-hangzhou.aliyuncs.com',
      'cn-hangzhou'
    );
    console.log('OSS client created successfully:', result);
  } catch (error) {
    console.error('Error creating OSS client:', error);
  }
}

createOSSClient();

Upload - Upload a file to OSS

Note

Before you call this method, initialize the OSS environment using env_init.

Golang

// Uploads a local file or folder to OSS.
func (o *Oss) Upload(bucket, object, path string) (*UploadResult, error)

Parameters:

  • bucket: The name of the OSS bucket.

  • object: The object key in OSS.

  • path: The path of the local file or folder.

Return values:

  • *UploadResult: An object that contains the upload URL and the request ID.

  • error: The error message if the operation fails.

UploadResult struct:

type UploadResult struct {
    RequestID string // A unique request identifier for debugging.
    URL       string // The URL of the uploaded file.
}

Example:

package main

import (
	"fmt"
	"os"

	"github.com/aliyun/wuying-agentbay-sdk/golang/pkg/agentbay"
)

func main() {
	// Initialize the SDK.
	client, err := agentbay.NewAgentBay("your_api_key", nil)
	if err != nil {
		fmt.Printf("Error initializing AgentBay client: %v\n", err)
		os.Exit(1)
	}

	// Step 1: Initialize the OSS environment.
	_, err = client.Oss.EnvInit(
		"your_access_key_id",
		"your_access_key_secret",
		"your_security_token",
		"oss-cn-hangzhou.aliyuncs.com",
		"cn-hangzhou",
	)
	if err != nil {
		fmt.Printf("Error initializing OSS environment: %v\n", err)
		os.Exit(1)
	}

	// Step 2: Upload the file to OSS.
	result, err := client.Oss.Upload("my-bucket", "my-object", "/path/to/local/file")
	if err != nil {
		fmt.Printf("Error uploading file: %v\n", err)
		os.Exit(1)
	}

	fmt.Printf("File uploaded successfully, URL: %s, request ID: %s\n", result.URL, result.RequestID)
}

Python

def upload(self, bucket: str, object: str, path: str) -> OSSUploadResult

Parameters:

  • bucket: The name of the OSS bucket.

  • object: The object key in OSS.

  • path: The path of the local file or folder.

Return value:

  • OSSUploadResult: A result object that contains the upload result, request ID, success status, and error message.

OSSUploadResult struct:

class OSSUploadResult(ApiResponse):
    def __init__(self, request_id: str = "", success: bool = False,
                 content: str = "", error_message: str = "")

Example:

from wuying_agentbay_sdk import AgentBay

# Initialize the SDK.
agent_bay = AgentBay(api_key="your_api_key")

# Step 1: Initialize the OSS environment.
agent_bay.oss.env_init(
    access_key_id="your_access_key_id",
    access_key_secret="your_access_key_secret",
    security_token="your_security_token",
    endpoint="oss-cn-hangzhou.aliyuncs.com",
    region="cn-hangzhou"
)

# Step 2: Upload the file.
result = agent_bay.oss.upload("my-bucket", "my-object", "/path/to/local/file")
print("File uploaded successfully:", result)

TypeScript

async upload(bucket: string, object: string, path: string): Promise<string>

Parameters:

  • bucket: The name of the OSS bucket.

  • object: The object key in OSS.

  • path: The path of the local file or folder.

Return value:

  • Promise<string>: The result of the upload operation.

Exception:

  • APIError: Thrown if the upload fails.

Example:

import { AgentBay } from 'wuying-agentbay-sdk';

// Initialize the SDK.
const agentBay = new AgentBay({ apiKey: 'your_api_key' });

async function uploadFile() {
  try {
    // Step 1: Initialize the OSS environment.
    await agentBay.oss.envInit(
      'your_access_key_id',
      'your_access_key_secret',
      'your_security_token',
      'oss-cn-hangzhou.aliyuncs.com',
      'cn-hangzhou'
    );
    // Step 2: Upload the file to OSS.
    const result = await agentBay.oss.upload('my-bucket', 'my-object', '/path/to/local/file');
    console.log('File uploaded successfully:', result);
  } catch (error) {
    console.error('Error uploading file:', error);
  }
}

uploadFile();

UploadAnonymous - Anonymously upload a file

Note

Before you call this method, initialize the OSS environment using env_init.

Golang

// Anonymously uploads a local file or folder to a specified URL.
func (o *Oss) UploadAnonymous(url, path string) (*UploadResult, error)

Parameters:

  • url: The HTTP or HTTPS URL.

  • path: The path of the local file or folder.

Return values:

  • *UploadResult: An object that contains the upload URL and the request ID.

  • error: The error message if the operation fails.

Example:

package main

import (
	"fmt"
	"os"

	"github.com/aliyun/wuying-agentbay-sdk/golang/pkg/agentbay"
)

func main() {
	// Initialize the SDK.
	client, err := agentbay.NewAgentBay("your_api_key", nil)
	if err != nil {
		fmt.Printf("Error initializing AgentBay client: %v\n", err)
		os.Exit(1)
	}

	// Step 1: Initialize the OSS environment.
	_, err = client.Oss.EnvInit(
		"your_access_key_id",
		"your_access_key_secret",
		"your_security_token",
		"oss-cn-hangzhou.aliyuncs.com",
		"cn-hangzhou",
	)
	if err != nil {
		fmt.Printf("Error initializing OSS environment: %v\n", err)
		os.Exit(1)
	}

	// Step 2: Anonymously upload the file.
	result, err := client.Oss.UploadAnonymous("https://example.com/upload", "/path/to/local/file")
	if err != nil {
		fmt.Printf("Error uploading file anonymously: %v\n", err)
		os.Exit(1)
	}

	fmt.Printf("File uploaded anonymously successfully, URL: %s, request ID: %s\n", result.URL, result.RequestID)
}

Python

def upload_anonymous(self, url: str, path: str) -> OSSUploadResult

Parameters:

  • url: The HTTP or HTTPS URL.

  • path: The path of the local file or folder.

Return value:

  • OSSUploadResult: A result object that contains the upload result, request ID, success status, and error message.

Example:

from agentbay import AgentBay

# Initialize the SDK.
agent_bay = AgentBay(api_key="your_api_key")

# Anonymously upload the file.
result = agent_bay.oss.upload_anonymous("https://example.com/upload", "/path/to/local/file")

if result.success:
    print(f"File uploaded anonymously successfully, content: {result.content}")
    print(f"Request ID: {result.request_id}")
else:
    print(f"Failed to upload file anonymously: {result.error_message}")

TypeScript

async uploadAnonymous(url: string, path: string): Promise<string>

Parameters:

  • url: The HTTP or HTTPS URL.

  • path: The path of the local file or folder.

Return value:

  • Promise<string>: The result of the upload operation.

Exception:

  • APIError: Thrown if the upload fails.

Example:

import { AgentBay } from 'wuying-agentbay-sdk';

// Initialize the SDK.
const agentBay = new AgentBay({ apiKey: 'your_api_key' });

async function uploadFileAnonymously() {
  try {
    // Step 1: Initialize the OSS environment.
    await agentBay.oss.envInit(
      'your_access_key_id',
      'your_access_key_secret',
      'your_security_token',
      'oss-cn-hangzhou.aliyuncs.com',
      'cn-hangzhou'
    );
    // Step 2: Anonymously upload the file.
    const result = await agentBay.oss.uploadAnonymous('https://example.com/upload', '/path/to/local/file');
    console.log('File uploaded anonymously successfully:', result);
  } catch (error) {
    console.error('Error uploading file anonymously:', error);
  }
}

uploadFileAnonymously();

Download - Download a file from OSS

Note

Before you call this method, initialize the OSS environment using env_init.

Golang

// Downloads an object from OSS to a local file.
func (o *Oss) Download(bucket, object, path string) (*DownloadResult, error)

Parameters:

  • bucket: The name of the OSS bucket.

  • object: The object key in OSS.

  • path: The local path where the file is saved.

Return values:

  • *DownloadResult: An object that contains the local file path and the request ID.

  • error: The error message if the operation fails.

DownloadResult struct:

type DownloadResult struct {
    RequestID string // A unique request identifier for debugging.
    LocalPath string // The local path where the file is downloaded.
}

Example:

package main

import (
	"fmt"
	"os"

	"github.com/aliyun/wuying-agentbay-sdk/golang/pkg/agentbay"
)

func main() {
	// Initialize the SDK.
	client, err := agentbay.NewAgentBay("your_api_key", nil)
	if err != nil {
		fmt.Printf("Error initializing AgentBay client: %v\n", err)
		os.Exit(1)
	}

	// Step 1: Initialize the OSS environment.
	_, err = client.Oss.EnvInit(
		"your_access_key_id",
		"your_access_key_secret",
		"your_security_token",
		"oss-cn-hangzhou.aliyuncs.com",
		"cn-hangzhou",
	)
	if err != nil {
		fmt.Printf("Error initializing OSS environment: %v\n", err)
		os.Exit(1)
	}

	// Step 2: Download the file from OSS.
	result, err := client.Oss.Download("my-bucket", "my-object", "/path/to/local/file")
	if err != nil {
		fmt.Printf("Error downloading file: %v\n", err)
		os.Exit(1)
	}

	fmt.Printf("File downloaded successfully to: %s, request ID: %s\n", result.LocalPath, result.RequestID)
}

Python

def download(self, bucket: str, object: str, path: str) -> OSSDownloadResult

Parameters:

  • bucket: The name of the OSS bucket.

  • object: The object key in OSS.

  • path: The local path where the file is saved.

Return value:

  • OSSDownloadResult: A result object that contains the download result, request ID, success status, and error message.

OSSDownloadResult struct:

class OSSDownloadResult(ApiResponse):
    def __init__(self, request_id: str = "", success: bool = False,
                 content: str = "", error_message: str = "")

Example:

from wuying_agentbay_sdk import AgentBay

# Initialize the SDK.
agent_bay = AgentBay(api_key="your_api_key")

# Step 1: Initialize the OSS environment.
agent_bay.oss.env_init(
    access_key_id="your_access_key_id",
    access_key_secret="your_access_key_secret",
    security_token="your_security_token",
    endpoint="oss-cn-hangzhou.aliyuncs.com",
    region="cn-hangzhou"
)

# Step 2: Download the file.
result = agent_bay.oss.download("my-bucket", "my-object", "/path/to/local/file")
print("File downloaded successfully:", result)

TypeScript

async download(bucket: string, object: string, path: string): Promise<string>

Parameters:

  • bucket: The name of the OSS bucket.

  • object: The object key in OSS.

  • path: The local path where the file is saved.

Return value:

  • Promise<string>: The result of the download operation.

Exceptions:

  • APIError: Thrown if the download fails.

Example:

import { AgentBay } from 'wuying-agentbay-sdk';

// Initialize the SDK.
const agentBay = new AgentBay({ apiKey: 'your_api_key' });

async function downloadFile() {
  try {
    // Step 1: Initialize the OSS environment.
    await agentBay.oss.envInit(
      'your_access_key_id',
      'your_access_key_secret',
      'your_security_token',
      'oss-cn-hangzhou.aliyuncs.com',
      'cn-hangzhou'
    );
    // Step 2: Download the file from OSS.
    const result = await agentBay.oss.download('my-bucket', 'my-object', '/path/to/local/file');
    console.log('File downloaded successfully:', result);
  } catch (error) {
    console.error('Error downloading file:', error);
  }
}

downloadFile();

DownloadAnonymous - Anonymously download a file

Note

Before you call this method, initialize the OSS environment using env_init.

Golang

// Anonymously downloads a file from a specified URL to a local path.
func (o *Oss) DownloadAnonymous(url, path string) (*DownloadResult, error)

Parameters:

  • url: The HTTP or HTTPS URL.

  • path: The full local path where the file is saved.

Return values:

  • *DownloadResult: An object that contains the local file path and the request ID.

  • error: The error message if the operation fails.

Example:

package main

import (
	"fmt"
	"os"

	"github.com/aliyun/wuying-agentbay-sdk/golang/pkg/agentbay"
)

func main() {
	// Initialize the SDK.
	client, err := agentbay.NewAgentBay("your_api_key", nil)
	if err != nil {
		fmt.Printf("Error initializing AgentBay client: %v\n", err)
		os.Exit(1)
	}

	// Step 1: Initialize the OSS environment.
	_, err = client.Oss.EnvInit(
		"your_access_key_id",
		"your_access_key_secret",
		"your_security_token",
		"oss-cn-hangzhou.aliyuncs.com",
		"cn-hangzhou",
	)
	if err != nil {
		fmt.Printf("Error initializing OSS environment: %v\n", err)
		os.Exit(1)
	}

	// Step 2: Anonymously download the file.
	result, err := client.Oss.DownloadAnonymous("https://example.com/file.txt", "/path/to/local/file.txt")
	if err != nil {
		fmt.Printf("Error downloading file anonymously: %v\n", err)
		os.Exit(1)
	}

	fmt.Printf("File downloaded anonymously successfully to: %s, request ID: %s\n", result.LocalPath, result.RequestID)
}

Python

def download_anonymous(self, url: str, path: str) -> OSSDownloadResult

Parameters:

  • url: The HTTP or HTTPS URL.

  • path: The local path where the file or folder is saved.

Return value:

  • OSSDownloadResult: A result object that contains the downloaded content, request ID, success status, and error message.

Example:

from agentbay import AgentBay

# Initialize the SDK.
agent_bay = AgentBay(api_key="your_api_key")

# Anonymously download the file.
result = agent_bay.oss.download_anonymous("https://example.com/file.txt", "/path/to/local/file.txt")

if result.success:
    print(f"File downloaded anonymously successfully, content: {result.content}")
    print(f"Request ID: {result.request_id}")
else:
    print(f"Failed to download file anonymously: {result.error_message}")

TypeScript

async downloadAnonymous(url: string, path: string): Promise<string>

Parameters:

  • url: The HTTP or HTTPS URL.

  • path: The full local path where the file is saved.

Return value:

  • Promise<string>: The result of the download operation.

Exceptions:

  • APIError: Thrown if the download fails.

Example:

import { AgentBay } from 'wuying-agentbay-sdk';

// Initialize the SDK.
const agentBay = new AgentBay({ apiKey: 'your_api_key' });

async function downloadFileAnonymously() {
  try {
    // Step 1: Initialize the OSS environment.
    await agentBay.oss.envInit(
      'your_access_key_id',
      'your_access_key_secret',
      'your_security_token',
      'oss-cn-hangzhou.aliyuncs.com',
      'cn-hangzhou'
    );
    // Step 2: Anonymously download the file.
    const result = await agentBay.oss.downloadAnonymous('https://example.com/file.txt', '/path/to/local/file.txt');
    console.log('File downloaded anonymously successfully:', result);
  } catch (error) {
    console.error('Error downloading file anonymously:', error);
  }
}

downloadFileAnonymously();