0.1.24 • Published 2 years ago
qdp2-oss v0.1.24
qdp2-oss-sdk
封装ali OSS 和 MinIO 的SDK。
NOTE: ali-oss@6.16.0,minio@7.0.18
Install
npm install --save qdp2-oss使用
method:
// 普通上传
put(initOptions, fileName, file, option)
// 分片上传(ali-oss)
multipartUpload(initOptions, fileName, file, option)
// 下载
// getPresigned(initOptions, fileName)
initOptions:
| 参数 | 说明 | 类型 | 默认值 |
|---|---|---|---|
| type | 选择sdk类型'aliyun' 'minio' | string | 'aliyun' |
| region | 选择aliyun时必填,对应ali-oss 的 region | string | -- |
| endpoint | 必填,对应ali-oss 的 endpoint,或 MinIO 的 endPoint | string | -- |
| bucket | 必填,对象存储的桶 | string | -- |
| tokenHost | 选择aliyun时必填,请求stsToken的接口地址 | string | -- |
| useSSL | minio,是否开启SSL,本地调试设为false | boolean | true |
| accessKey | minio时必填,账号 | string | -- |
| secretKey | minio时必填,密码 | string | -- |
example:
// 标品
{
"type": 'aliyun',
"region": 'xxx',
"endpoint": 'xxxxx.aliyuncs.com',
"bucket": 'xxxxxxx',
"tokenHost": 'http://xxxxx/xxxxx/xxxxx',
}
// ka
{
"type": 'minio',
"endpoint": 'xxx.xx.xx',
"useSSL": false,
"accessKey": 'xxxxxxx',
"secretKey": 'xxxxxxxx',
"bucket": 'xxxxxxx',
}fileName: 上传文件名称,包含存放路径
file: 文件
option: 对应ali-oss 方法的option
完整example:
import * as qdp2OSS from "qdp2-oss";
const options = process.env.oss;
const fileName = `xxxx/${Date.now()}_${Math.trunc(Math.random() * 10000)}_${file.name}`;
qdp2OSS.put(options, fileName, file)
.then((result) => {
console.log(result);
})
.catch((err) => {
});