oss-upload-tool
v0.9.0
Published
Integrated oss upload
Maintainers
Readme
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-devUsing yarn:
yarn add oss-upload-tool -DUsage
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_regionGet 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:
boolDelete the directory structure of uploaded files. - rename:
string | (path: string, ext: string) => stringUploaded file name. - transform:
(Buffer) => Buffer | stringUpload file content.
- src:
type
- Type:
COS | ALI | S3defaultCOS
uploadParams
- COS
import('cos-nodejs-sdk-v5').SliceUploadFileParams - ALI
import('ali-oss').PutObjectOptions - S3
import('aws-sdk').S3.Types.PutObjectRequest
COSOptions
- Type:
objecthttps://github.com/tencentyun/cos-nodejs-sdk-v5
ALIOptions
- Type:
objecthttps://github.com/ali-sdk/ali-oss#node-usage
S3Options
- Type:
objecthttps://docs.aws.amazon.com/AWSJavaScriptSDK/v3/latest/index.html
parallelLimit
- Type:
numberdefault5
Number of parallel uploads.
origin
- Type:
string
The current CDN externally accesses the domain name, which needs to have an agreement.
existCheckcheck, if the default cdn domain name cannot be accessed, use the open access cdn domain name to check
timeout
- Type:
numberdefault1000 * 60 * 30
Single file upload timeout
existCheck
- Type:
boolean | patternsdefaultfalse
Specify the file. If the file exists, skip the upload. The judgment is to useetagfirst. If there is noetag, 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:
numberdefault0
Maximum number of failed retries.
cwd
- Type:
stringdefaultprocess.cwd()
