aliyun-oss
A fully async, type-safe Rust SDK for Alibaba Cloud Object Storage Service (OSS).
Features
- Async-first — Built on
tokioandreqwest, all network I/O is non-blocking - V4 Sigining — HMAC-SHA256 request signing with known-answer test verification
- V1 Sigining — HMAC-SHA1 signing for legacy compatibility
- Pre-signed URLs — Generate time-limited download URLs without sharing credentials
- Full Object CRUD — Put, Get, Head, Delete, Copy, Append with metadata, ACL, and SSE support
- Multipart Upload — Initiate, upload parts (with automatic Content-MD5), copy parts, complete, and abort
- Bucket Configuration — Lifecycle, CORS, policy, encryption, versioning, logging, website, referer, tagging, replication, WORM, TLS, and more
- Type-safe — Newtype wrappers for bucket names, object keys, ETags, regions, and storage classes
- Credentials Chain — Environment variables, static credentials, and custom provider support
- Rich Error Handling — Structured error types with OSS service error parsing and contextual information
Installation
Add to your Cargo.toml:
[]
= "0.2"
= { = "1", = ["full"] }
Quick Start
use OSSClient;
use Region;
async
Authentication
Credentials can be provided in several ways:
use ;
// From environment variables (OSS_ACCESS_KEY_ID, OSS_ACCESS_KEY_SECRET)
let provider = new;
// Chained fallback: try env first, then static
let chain = builder
.with
.with
.build;
// Or directly in the builder
let client = builder
.region
.credentials
.build?;
For STS temporary credentials:
let creds = builder
.access_key_id
.access_key_secret
.security_token
.build?;
Object Operations
Basic CRUD
let bucket = client.bucket?;
// Put
let put = bucket.put_object?
.body
.content_type
.acl
.storage_class
.metadata
.send.await?;
// Get
let get = bucket.get_object?
.range
.if_match
.send.await?;
// Head (metadata only, no body)
let head = bucket.head_object?
.send.await?;
// Delete
bucket.delete_object?.send.await?;
Copy
bucket.put_object?
.copy_source
.send.await?;
Append
bucket.append_object? // position = 0 for first append
.body
.send.await?;
bucket.append_object? // position = current object size
.body
.send.await?;
List Objects
// V1 listing
let objects = bucket.list_objects
.prefix
.delimiter
.max_keys
.send.await?;
// V2 listing (supports continuation token)
let objects = bucket.list_objects_v2
.prefix
.start_after
.max_keys
.send.await?;
// List all versions (requires versioning enabled)
let versions = bucket.list_object_versions
.prefix
.max_keys
.send.await?;
Tagging
bucket.put_object_tagging?
.tag
.tag
.send.await?;
let tags = bucket.get_object_tagging?.send.await?;
bucket.delete_object_tagging?.send.await?;
Object ACL
// Get ACL
let acl = bucket.get_object_acl?.send.await?;
// Set ACL
bucket.put_object_acl?.send.await?;
Symlink
bucket.put_symlink?.send.await?;
let sym = bucket.get_symlink?.send.await?;
Restore (Archive/ColdArchive)
bucket.restore_object? // restore for 3 days
.tier
.send.await?;
Batch Delete
let result = bucket.delete_multiple_objects.quiet.send.await?;
Image Processing
let processed = bucket.process_object?
.send.await?;
Multipart Upload
For files larger than 5 GiB or when resumable upload is needed:
// Initiate
let init = bucket.initiate_multipart_upload?
.content_type
.send.await?;
// Upload parts (Content-MD5 is computed automatically)
let part1 = bucket.upload_part?
.body
.send.await?;
let part2 = bucket.upload_part?
.body
.send.await?;
// Copy a part from another object
let copied = bucket.upload_part_copy?
.copy_source
.send.await?;
// Complete
let complete = bucket.complete_multipart_upload?
.part
.part
.part
.send.await?;
// List parts
let parts = bucket.list_parts?
.max_parts
.send.await?;
// List all multipart uploads
let uploads = bucket.list_multipart_uploads
.max_uploads
.send.await?;
// Abort if needed
bucket.abort_multipart_upload?
.send.await?;
Bucket Operations
Create and manage
// Create a bucket
bucket.create
.acl
.storage_class
.data_redundancy
.send.await?;
// Get bucket info
let info = bucket.get_info.send.await?;
// Get bucket statistics
let stat = bucket.get_stat.send.await?;
// Delete bucket
bucket.delete.send.await?;
Access Control
bucket.put_acl.send.await?;
let acl = bucket.get_acl.send.await?;
Versioning
bucket.put_versioning.send.await?;
let status = bucket.get_versioning.send.await?;
Lifecycle
let rules = vec!;
bucket.put_lifecycle.send.await?;
let rules = bucket.get_lifecycle.send.await?;
bucket.delete_lifecycle.send.await?;
CORS
bucket.put_cors.send.await?;
let rules = bucket.get_cors.send.await?;
bucket.delete_cors.send.await?;
Policy, Encryption, Website, Logging, Referer, Tags
bucket.put_policy.send.await?;
let policy = bucket.get_policy.send.await?;
bucket.put_encryption.send.await?;
bucket.put_website?
.error_document
.send.await?;
bucket.put_logging
.target_bucket
.target_prefix
.send.await?;
bucket.put_referer
.add_referer
.send.await?;
bucket.put_tags
.tag
.tag
.send.await?;
Pre-signed URLs
Generate time-limited URLs for sharing objects without exposing credentials:
// Build a pre-signed GET URL (valid for 1 hour)
let url = client
.presign.await
.method
.expires
.query_param
.generate
.await?;
println!;
// V4 pre-signed URL
let v4_url = client
.presign
.generate_v4?;
Service Operations
// List all buckets
let buckets = client.list_buckets?
.prefix
.max_keys
.send
.await?;
Error Handling
All fallible operations return aliyun_oss::error::Result<T>, which is an alias for std::result::Result<T, OssError>.
use ;
match client.bucket?.get_object?.send.await
Regions
Supported regions via the Region enum:
use Region;
CnHangzhou // oss-cn-hangzhou.aliyuncs.com
CnShanghai // oss-cn-shanghai.aliyuncs.com
CnBeijing // oss-cn-beijing.aliyuncs.com
CnShenzhen // oss-cn-shenzhen.aliyuncs.com
ApSingapore // oss-ap-southeast-1.aliyuncs.com
// ... 37+ regions supported
// Custom endpoint
Custom
Minimum Supported Rust Version
Rust 1.85+ (Edition 2024).
License
This project is licensed under the MIT License.