项目中使用到上传文件功能,网上搜索了下选择使用阿里云oss上传,查看官方文档。
账号配置:
let OSS = require("ali-oss");
let client = new OSS({
region: "oss-cn-beijing",
accessKeyId: "xxxxx",
accessKeySecret: "xxxxx",
bucket: "xxxxx"
});
if (!client) {
this.$emit("error", { msg: "oss初始化未完成" });
return;
}
上传
client
.multipartUpload(storePath, file)
.then(response => {
console.log(response);
if (response.res.status === 200) {
} else {
}
})
.catch(error => {
console.log(error);
});
OK!开始上传,发现返回跨域错误,搜索查看发现要进行跨域配置,设置来源origin允许当前域名即可。
网友评论