0.9.0 • Published 5 months ago

oss-upload-tool v0.9.0

Weekly downloads
-
License
MIT
Repository
github
Last release
5 months ago

npm size test NPM downloads

oss-upload-tool

Integrated oss upload
Complete integration COS-OSS / ALI-OSS / S3-OSS, Welcome to improve together.

Install

Using npm:

npm install oss-upload-tool --save-dev

Using yarn:

yarn add oss-upload-tool -D

Usage

The tool will prioritize the identification of environment variables for easy invocation.
Before use, please register environment variables in advance to facilitate use. In CI/Action, you can set environment variables to prevent exposure of OSS parameters.

# General parameters
npm config --global set oss_upload_tool_secret_id "your secret_id"
npm config --global get oss_upload_tool_secret_key "your secret_key"
npm config --global get oss_upload_tool_bucket "your bucket"
npm config --global get oss_upload_tool_region "your region"

There are the following environment variables.
It is recommended to set the environment variable corresponding to oss first, then you do not need to specify the type of oss service provider.

# General parameters
npm config get oss_upload_tool_secret_id
npm config get oss_upload_tool_secret_key
npm config get oss_upload_tool_bucket
npm config get oss_upload_tool_region
# cos-oss
npm config get oss_upload_tool_cos_secret_id
npm config get oss_upload_tool_cos_secret_key
npm config get oss_upload_tool_cos_bucket
npm config get oss_upload_tool_cos_region
# ali-oss
npm config get oss_upload_tool_alioss_secret_id
npm config get oss_upload_tool_alioss_secret_key
npm config get oss_upload_tool_alioss_bucket
npm config get oss_upload_tool_alioss_region
npm config get oss_upload_tool_alioss_endpoint
# s3-oss
npm config get oss_upload_tool_s3_secret_id
npm config get oss_upload_tool_s3_secret_key
npm config get oss_upload_tool_s3_bucket
npm config get oss_upload_tool_s3_region

Get parameter priority parameters > process.env.[key] > npm config get [key].

Usage in CLI

oss-upload-tool -t "./lib/**" -d "./__xxx","__xxx1/" --bucket "***" --region "***" --oss "S3"

Usage in Node

const ossUpload = require('oss-upload-tool');

// upload cos-oss
await ossUpload({
  targets: {
    src: './lib/**/*',
    dest: ['__xxx/', '__xxx1/'],
  },
  uploadParams: {
    Bucket: '***',
    Region: '***',
  },
  COSOptions: {
    SecretId: '***',
    SecretKey: '***',
  },
});

// upload ali-oss
await ossUpload({
  targets: {
    src: './lib/**/*',
    dest: ['__xxx/', '__xxx1/'],
  },
  ALIOptions: {
    accessKeyId: '***',
    accessKeySecret: '***',
    bucket: '***',
    region: '***',
    endpoint: '***',
  },
});

// upload s3-oss
ossUpload({
  targets: {
    src: './lib/**/*',
    dest: ['__xxx/', '__xxx1/'],
  },
  uploadParams: {
    Bucket: '***',
  },
  S3Options: {
    credentials: {
      accessKeyId: '***',
      secretAccessKey: '***',
    },
    region: '***',
  },
})

Options

targets

Upload configuration

  • Type: array | object
    • src: string | string[] globby patterns.
    • dest: string | string[] Upload path, If it is an array, it will upload to multiple directories.
    • flatten: bool Delete the directory structure of uploaded files.
    • rename: string | (path: string, ext: string) => string Uploaded file name.
    • transform: (Buffer) => Buffer | string Upload file content.

type

  • Type: COS | ALI | S3 default COS

uploadParams

  • COS import('cos-nodejs-sdk-v5').SliceUploadFileParams
  • ALI import('ali-oss').PutObjectOptions
  • S3 import('aws-sdk').S3.Types.PutObjectRequest

COSOptions

ALIOptions

S3Options

parallelLimit

  • Type: number default 5
    Number of parallel uploads.

origin

  • Type: string
    The current CDN externally accesses the domain name, which needs to have an agreement.

    existCheck check, if the default cdn domain name cannot be accessed, use the open access cdn domain name to check

timeout

  • Type: number default 1000 * 60 * 30
    Single file upload timeout

existCheck

  • Type: boolean | patterns default false
    Specify the file. If the file exists, skip the upload. The judgment is to use etag first. If there is no etag, as long as the request returns 200, it will be skipped.
    By default, the official domain name of oss is used to access. If it cannot be accessed, please specify origin to set a custom domain name.

maxAttempts

  • Type: number default 0
    Maximum number of failed retries.

cwd

  • Type: string default process.cwd()
0.9.0

5 months ago

0.8.0

5 months ago

0.6.6

1 year ago

0.7.0

1 year ago

0.6.5

2 years ago

0.6.3

2 years ago

0.6.2

2 years ago

0.4.7

2 years ago

0.6.4

2 years ago

0.4.6

2 years ago

0.5.0

2 years ago

0.6.1

2 years ago

0.6.0

2 years ago

0.5.1

2 years ago

0.4.5

2 years ago

0.4.4

2 years ago

0.4.3

2 years ago

0.4.2

2 years ago

0.4.1

2 years ago

0.4.0

2 years ago

0.3.0

2 years ago

0.2.21

2 years ago

0.2.20

2 years ago

0.2.19

2 years ago

0.2.18

2 years ago

0.2.17

2 years ago

0.2.16

2 years ago

0.2.15

2 years ago

0.2.14

2 years ago

0.2.13

2 years ago

0.2.12

2 years ago

0.2.11

2 years ago

0.2.10

2 years ago

0.2.9

2 years ago

0.2.8

2 years ago

0.2.7

2 years ago

0.2.6

2 years ago

0.2.5

2 years ago

0.2.4

2 years ago

0.2.3

2 years ago

0.2.1

2 years ago

0.2.0

2 years ago

0.1.1

2 years ago

0.1.0

2 years ago