1.2.3 • Published 1 year ago
gc_cos_lib v1.2.3
绿云上传基本类库
简介
支持上传到七牛、阿里云、腾讯云并记录日志
安装
npm install gc_cos_lib --save
使用
直接使用
import UploadFile from "gc_cos_lib"
// 普通上传
const file = file // iview中beforeUpload 事件中获取,注意返回false阻止默认上传
// uniapp中获取文件
const file = res.tempFiles[0];
const upload = new UploadFile({
file, // 需要上传的文件
env: process.env.NODE_ENV, // 环境变量,与地址服务中配置的name一致
unitCode: "GCBZG",
fileType: "IMAGE" // 上传类型
});
const res = await upload.upload(); //上传并记录日志,详见res数据实力
if (res.success) {
// do something
}
// or 手动记录日志
const res = await upload.upload(false); //上传并手动记录日志
if (res.success) {
// do something
upload.record({id:123}); // 记录日志 并带入自定义数据
}
// 上传进度显示 目前只支持七牛云
const res = await upload.upload(false,(res)=>{
const { percent } = res;
// 上传进度处理
});
分离使用
// 无上传 单纯记日志(删除、修改等)
const upload = new UploadFile({
env: "development",
unitCode: "GREENCLOUD"
});
console.log(upload);
const res = await upload.record({ id: 123 });
res 回复数据示例
{
"success": true, // 上传是否成功 失败为false
"name": "1701242697159.jpg", // 图片名字
"url": "https://imokkkk-1305920415.cos.ap-shanghai.myqcloud.com/static/user/1701851395115_1701242697159.jpg", // 上传后正式访问地址
"channel": "TENCENT", // 上传渠道
"fileType": "OTHER" // 上传类型
}
参数说明
属性 | 说明 | 类型 | 默认值 |
---|---|---|---|
file | 上传的文件 | file | / |
dataPath | axios返回数据路径 | string | data |
point | 点位信息 | Object | {system: "UC", page: "USER",position: "Avatar",bizRelObject: "用户", bizRelObjectId: "user111" } |
fileType | 类型: 图片、视频、文件(IMAGE/VIDEO/OTHER ) | String | IMAGE |
unitCode | UC单位信息,不传token可以传这个 | String | / |
env | 当前环境变量 development、production等 对应地址服务name | String | development |
token | 绿云uctoken,与上两个参数互斥,只支持浏览器环境使用 | String | / |
useOriginFileName | 是否采用原有文件名 | String | false |
独立上传
const upload = new UploadFile({
file,
fileType: "IMAGE" // 上传类型
});
const res = await upload.uploadFile({
channel: "QINIU", // 上传渠道 QINIU、TENCENT、ALIYUN,必填
domain: "https://dev-ht-img.songtsam.com", // 七牛云链接域名,可选 可自己拼接
path: "base_journey/emergency/jugement/", // 七牛云存储位置,QINIU必填
token: "123", // 七牛云上传token,QINIU必填
host: "123" // 腾讯云或者阿里云签名上传地址,TENCENT、ALIYUN,必填
});
1.2.3
1 year ago
1.2.2
1 year ago
1.2.1
1 year ago
1.2.0
1 year ago
1.1.5
1 year ago
1.1.4
1 year ago
1.1.3
1 year ago
1.1.1
2 years ago
1.1.0
2 years ago
1.1.2
2 years ago
1.0.11
2 years ago
1.0.12
2 years ago
1.0.10
2 years ago
1.0.9
2 years ago
1.0.2
2 years ago
1.0.8
2 years ago
1.0.7
2 years ago
1.0.6
2 years ago
1.0.5
2 years ago
1.0.4
2 years ago
1.0.3
2 years ago
1.0.1
2 years ago
1.0.0
2 years ago