npm/cnpm install ali-oss --save
ossClient.js
const OSS = require('ali-oss');
export default function Client(data='custom-data') {
// console.log('bucket',data)
return new OSS({
region: "custom-region",
accessKeyId: "custom-accessKeyId",
accessKeySecret: "custom-accessKeySecret",
bucket: data
})
}
import Client from "@/utils/ossClient"
async uploadFiles(path, fileObject){
let client = Client()
// 可以自定义bucket let client = Client(‘custom-bucket’)
let fname = `${new Date().getTime()}.png` //自定义文件名
try {
// object-name可以自定义为文件名(例如file.txt)或目录(例如abc/test/file.txt)的形式,
// 实现将文件上传至当前Bucket或Bucket下的指定目录。
const result = await client.multipartUpload(fname, fileObject, {
// progress,
});
console.log(result);
} catch (e) {
console.log(e);
}
}
注意; 终止上传可以用client.cancel()