💡 Async Version: This documentation covers the synchronous API. For async/await support, see
AsyncOsswhich provides the same functionality with async methods.
- OSS Integration Guide - Integrate with Alibaba Cloud OSS for file storage
class OSSClientResult(ApiResponse)Result of OSS client creation operations.
def __init__(self, request_id: str = "",
success: bool = False,
client_config: Optional[Dict[str, Any]] = None,
error_message: str = "")Initialize an OSSClientResult.
Arguments:
request_idstr, optional - Unique identifier for the API request. Defaults to "".successbool, optional - Whether the operation was successful. Defaults to False.client_configDict[str, Any], optional - OSS client configuration. Defaults to None.error_messagestr, optional - Error message if the operation failed. Defaults to "".
class OSSUploadResult(ApiResponse)Result of OSS upload operations.
def __init__(self, request_id: str = "",
success: bool = False,
content: str = "",
error_message: str = "")Initialize an OSSUploadResult.
Arguments:
request_idstr, optional - Unique identifier for the API request. Defaults to "".successbool, optional - Whether the operation was successful. Defaults to False.contentstr, optional - Result of the upload operation. Defaults to "".error_messagestr, optional - Error message if the operation failed. Defaults to "".
class OSSDownloadResult(ApiResponse)Result of OSS download operations.
def __init__(self, request_id: str = "",
success: bool = False,
content: str = "",
error_message: str = "")Initialize an OSSDownloadResult.
Arguments:
request_idstr, optional - Unique identifier for the API request. Defaults to "".successbool, optional - Whether the operation was successful. Defaults to False.contentstring, optional - Defaults to "Download success"error_messagestr, optional - Error message if the operation failed. Defaults to "".
class Oss(BaseService)Handles Object Storage Service operations in the AgentBay cloud environment.
def __init__(self, session)Initialize an Oss object.
Arguments:
session: The Session instance that this Oss belongs to.
def env_init(access_key_id: str,
access_key_secret: str,
security_token: str,
endpoint: Optional[str] = None,
region: Optional[str] = None) -> OSSClientResultCreate an OSS client with the provided STS temporary credentials.
Arguments:
access_key_id: The Access Key ID from STS temporary credentials.
access_key_secret: The Access Key Secret from STS temporary credentials.
security_token: Security token from STS temporary credentials. Required for security.
endpoint: The OSS service endpoint. If not specified, the default is used.
region: The OSS region. If not specified, the default is used.
Returns:
OSSClientResult: Result object containing client configuration and error
message if any.
Example:
session = agent_bay.create().session
session.oss.env_init(
access_key_id="your_sts_access_key_id",
access_key_secret="your_sts_access_key_secret",
security_token="your_sts_security_token"
)
session.delete()def upload(bucket: str, object: str, path: str) -> OSSUploadResultUpload a local file or directory to OSS.
Note: Before calling this API, you must first call env_init to initialize the OSS environment.
Arguments:
bucket: OSS bucket name.
object: Object key in OSS.
path: Local file or directory path to upload.
Returns:
OSSUploadResult: Result object containing upload result and error message
if any.
Example:
session = agent_bay.create().session
session.oss.env_init(
access_key_id="your_access_key_id",
access_key_secret="your_access_key_secret",
security_token="your_sts_security_token",
)
result = session.oss.upload("my-bucket", "file.txt", "/local/path/file.txt")
print(f"Upload result: {result.content}")
session.delete()def upload_anonymous(url: str, path: str) -> OSSUploadResultUpload a local file or directory to a URL anonymously.
Arguments:
url: The HTTP/HTTPS URL to upload the file to.
path: Local file or directory path to upload.
Returns:
OSSUploadResult: Result object containing upload result and error message
if any.
Example:
session = agent_bay.create().session
result = session.oss.upload_anonymous(
"https://example.com/upload",
"/local/path/file.txt"
)
print(f"Upload result: {result.content}")
session.delete()def download(bucket: str, object: str, path: str) -> OSSDownloadResultDownload an object from OSS to a local file or directory.
Note: Before calling this API, you must first call env_init to initialize the OSS environment.
Arguments:
bucket: OSS bucket name.
object: Object key in OSS.
path: Local file or directory path to download to.
Returns:
OSSDownloadResult: Result object containing download status and error
message if any.
Example:
session = agent_bay.create().session
session.oss.env_init(
access_key_id="your_access_key_id",
access_key_secret="your_access_key_secret",
security_token="your_sts_security_token",
)
result = session.oss.download("my-bucket", "file.txt", "/local/path/file.txt")
print(f"Download result: {result.content}")
session.delete()def download_anonymous(url: str, path: str) -> OSSDownloadResultDownload a file from a URL anonymously to a local file path.
Arguments:
url: The HTTP/HTTPS URL to download the file from.
path: Local file or directory path to download to.
Returns:
OSSDownloadResult: Result object containing download status and error
message if any.
Example:
session = agent_bay.create().session
result = session.oss.download_anonymous(
"https://example.com/file.txt",
"/local/path/file.txt"
)
print(f"Download result: {result.content}")
session.delete()Related APIs:
Documentation generated automatically from source code using pydoc-markdown.