安裝 ali-oss
npm install ali-oss
實例
import OSS from 'ali-oss';
export default (conf) => {
return new OSS(conf);
}
import ossClient from '對應文件地址/oss.js';
let uploadConf = {
region: null,
accessKeyId: null,
accessKeySecret: null,
bucket: null,
stsToken: null
}
uploadHttp (file) {
ossClient(uploadConf)
.put(`'上傳目錄'/${new Date().getTime()+'.'+'圖片格式'}`, file, {'ContentType': 'image/jpeg' })
.then(({res, url, name}) => {
if (res && res.status == 200) {
console.log(`阿里雲OSS上傳圖片成功回調`, res, url, name);
console.log(`阿里雲OSS上傳圖片成功回調`, 返回實體, 返回地址, 返回圖片的名稱);
const url = ossClient(uploadConf).signatureUrl(name, {
process: 'image/resize,w_200'
})
}
}).catch((err) => {
console.log(`阿里雲OSS上傳圖片失敗回調`, err);
});
}