Alibaba Cloud Object Storage Service client library for Node.js and browser environments
npx @tessl/cli install tessl/npm-ali-oss@6.23.0ali-oss is a comprehensive JavaScript client library for Alibaba Cloud Object Storage Service (OSS) that enables developers to interact with cloud object storage from both Node.js and browser environments. It provides a full-featured API for managing buckets, uploading and downloading objects, handling multipart uploads, managing object metadata and permissions, and performing advanced operations like streaming, progress tracking, and STS token management.
npm install ali-oss --saveconst OSS = require('ali-oss');import OSS from 'ali-oss';<script src="./node_modules/ali-oss/dist/aliyun-oss-sdk.min.js"></script>
<script>
// OSS is available as global variable
const store = new OSS({ /* options */ });
</script>const OSS = require('ali-oss');
const store = new OSS({
region: 'oss-cn-hangzhou',
accessKeyId: 'your-access-key-id',
accessKeySecret: 'your-access-key-secret',
bucket: 'your-bucket-name'
});// Upload an object
const result = await store.put('my-object.txt', 'Hello, World!');
console.log('Upload result:', result);
// Download an object
const object = await store.get('my-object.txt');
console.log('Downloaded content:', object.content.toString());
// List objects
const list = await store.list();
console.log('Objects:', list.objects);
// Delete an object
await store.delete('my-object.txt');const store = new OSS({
region: 'oss-cn-hangzhou',
accessKeyId: 'your-sts-access-key',
accessKeySecret: 'your-sts-access-secret',
stsToken: 'your-sts-token',
bucket: 'your-bucket-name'
});ali-oss is built around several key components:
Core client setup, authentication, and configuration options. Essential for initializing OSS connections and managing client settings.
function OSS(options: ClientOptions): OSSClient;
interface ClientOptions {
region?: string;
accessKeyId: string;
accessKeySecret: string;
stsToken?: string;
bucket?: string;
endpoint?: string;
timeout?: number;
agent?: Agent;
httpsAgent?: Agent;
maxSockets?: number;
}Comprehensive bucket operations including creation, configuration, access control, and advanced features like lifecycle management, CORS, and encryption.
async function listBuckets(query?: ListBucketsQuery, options?: RequestOptions): Promise<ListBucketsResult>;
async function useBucket(name: string): void;
async function getBucketInfo(name: string, options?: RequestOptions): Promise<BucketInfo>;
async function deleteBucket(name: string, options?: RequestOptions): Promise<DeleteBucketResult>;Core object storage operations for uploading, downloading, and managing files. Includes metadata handling, access control, and URL generation.
async function put(name: string, file: ObjectSource, options?: PutObjectOptions): Promise<PutObjectResult>;
async function get(name: string, file?: string | WriteStream, options?: GetObjectOptions): Promise<GetObjectResult>;
async function delete(name: string, options?: RequestOptions): Promise<DeleteObjectResult>;
async function list(query?: ListObjectsQuery, options?: RequestOptions): Promise<ListObjectsResult>;High-performance multipart upload capabilities for large files with automatic part management, progress tracking, and resume functionality.
async function multipartUpload(name: string, file: ObjectSource, options?: MultipartUploadOptions): Promise<MultipartUploadResult>;
async function initMultipartUpload(name: string, options?: InitMultipartUploadOptions): Promise<InitMultipartUploadResult>;
async function uploadPart(name: string, uploadId: string, partNumber: number, file: ObjectSource, start?: number, end?: number, options?: RequestOptions): Promise<UploadPartResult>;Specialized image processing operations including transformations, EXIF data extraction, and style management for images stored in OSS.
function ImageClient(options: ImageClientOptions): ImageClient;
interface ImageClient {
async get(name: string, file?: string, options?: ImageGetOptions): Promise<ImageGetResult>;
async getInfo(name: string, options?: RequestOptions): Promise<ImageInfo>;
async putStyle(styleName: string, style: ImageStyle, options?: RequestOptions): Promise<PutStyleResult>;
}RTMP live streaming capabilities for creating and managing live channels, controlling streaming status, and generating VOD content.
async function putChannel(id: string, conf: ChannelConfig, options?: RequestOptions): Promise<PutChannelResult>;
async function getChannelStatus(id: string, options?: RequestOptions): Promise<ChannelStatus>;
async function createVod(id: string, name: string, time: VodTime, options?: RequestOptions): Promise<CreateVodResult>;STS operations for obtaining temporary credentials and assuming roles for secure, time-limited access to OSS resources.
function STS(options: STSOptions): STSClient;
interface STSClient {
async assumeRole(role: string, policy?: string, expiration?: number, session?: string, options?: RequestOptions): Promise<AssumeRoleResult>;
}High-availability cluster client providing automatic failover, load balancing, and health checking across multiple OSS endpoints.
function ClusterClient(options: ClusterOptions): ClusterClient;
interface ClusterOptions {
clusters: ClusterConfig[];
schedule?: 'roundRobin' | 'masterSlave';
retryMax?: number;
retryDelay?: number;
}