Upload directories to Alibaba Cloud OSS

Configure and run aliyunoss-cli to recursively upload a local directory to Alibaba Cloud OSS with environment-specific source and target paths.

npm install --save-dev aliyunoss-cli

Install

Install the command as a development dependency in the project that produces the directory you want to upload. The package requires Node.js 22 or later.

npm install --save-dev aliyunoss-cli

Run npx aliyunoss-cli --help to inspect the available options without uploading files.

Configure and run an upload

The command loads the base JSON configuration, merges the selected releaseEnvConf entry, and then applies explicit command-line flags. Required values are region, accessKeyId, accessKeySecret, bucket, source, and target.

Configuration file

{
  "region": "oss-region-id",
  "accessKeyId": "your-access-key-id",
  "accessKeySecret": "your-access-key-secret",
  "bucket": "your-bucket",
  "releaseEnvConf": {
    "production": {
      "source": "dist/",
      "target": "static/"
    }
  }
}

Command

npx aliyunoss-cli --releaseEnv production

Use explicit flags such as --source and --target when a run must override the selected environment.

Keep credentials out of source control. Store real access keys only in protected local or CI configuration.

Package and command behavior

The executable recursively walks the configured local source directory and uploads files beneath the configured OSS target path. The package root continues to expose the Alibaba Cloud OSS client constructor for programmatic use.

Environment overrides

Keep reusable base credentials and bucket settings separate from environment-specific source and target paths.

Explicit precedence

Command-line flags override the selected environment, which overrides the base JSON configuration.

Controlled examples

The browser example constructs the public OSS client with placeholders and never starts an upload or network request.

Install the documentation website

Supporting browsers can install this website for quick access to the guide, examples, and API documentation. The service worker is registered only on the production GitHub Pages path.