npm install ali-oss
import OSS from "ali-oss";
let GetOssFileClient = new OSS({
secure:true,
region: "你的阿里云地区", //例如:oss-cn-hangzhou
accessKeyId: "你的阿里云Id",
accessKeySecret: "你的阿里云Secret",
bucket: "你的阿里云仓库名",
});
async uploadOImg(obj){
let objItem = {uid: 0,name: '',status: 'done',url: '',}
let imgType = obj.type === 'image/jpeg'?'.jpg':'.png'
let storeAs = "/" + new Date().getTime() + imgType;
await GetOssFileClient.multipartUpload(storeAs, obj).then(function (result) {
objItem.name = storeAs
objItem.url = result.res.requestUrls[0]
}).catch(function (err) {
notification['error']({ message: '上传失败',description:'图片上传失败,请稍后再试' })});
return objItem
}
handlePreview = (obj) => {
let fileList = this.state.fileList
this.uploadOImg(obj).then(res=>{
console.log(res) // 图片地址
}
return false
};