Commit 025935b3 authored by zhengke's avatar zhengke

增加阿里云上传

parent 164522a7
......@@ -58,8 +58,8 @@ export default {
let javaUrl = 'http://192.168.2.65:8018';
// domainUrl = "http://192.168.1.27:8200";
domainUrl = "http://192.168.1.5:8088";
//domainUrl = "http://192.168.1.21";
//domainUrl = "http://192.168.1.13:8088";
domainUrl = "http://192.168.1.21";
//domainUrl = "https://localhost:5001";
let vtUploadUrl = "http://192.168.1.214:8120";
......@@ -181,6 +181,7 @@ export default {
//上传文件到云存储
Vue.prototype.UploadFileToTencent = function (path, fileObj, callback) {
// debugger;
var upInfo = JSON.parse(localStorage.uploadInfo);
if (fileObj.type == "image/png" || fileObj.type == "image/jpeg") {
let that = this
lrz(fileObj, {
......@@ -200,19 +201,111 @@ export default {
var newFile = new File([u8arr], fileObj.name, {
type: mime
});
that.uploadStart(path, newFile, callback)
if(upInfo.IsDefault==1){
that.uploadStart(path, newFile, callback)
}else{
this.Error('请先配置上传');
}
}).catch(function (error) {
that.uploadStart(path, fileObj, callback)
if(upInfo.IsDefault==1){
if(upInfo.StoreType==1){
that.uploadStart(path, newFile, callback)
}
if(upInfo.StoreType==3){
that.uploadToAli(path, newFile, callback)
}
}else{
this.Error('请先配置上传');
}
}).always(function () {
//不管成功或失败,都会执行
})
}else{
this.uploadStart(path, fileObj, callback)
if(upInfo.IsDefault==1){
if(upInfo.StoreType==1){
this.uploadStart(path, fileObj, callback)
}
if(upInfo.StoreType==3){
this.uploadToAli(path, fileObj, callback)
}
}else{
this.Error('请先配置上传');
}
}
},
Vue.prototype.uploadStart = function (path, fileObj, callback) {
var upInfo = JSON.parse(localStorage.uploadInfo);
if(upInfo.IsDefault==1){
//获取文件扩展名
var filename = fileObj.name;
var index = filename.lastIndexOf(".");
var suffix = filename.substr(index);
var timestamp1 = Date.parse(new Date()) + "_" + (Math.ceil(Math.random() * 1000));
let str = '';
if (this.isOnline()) {
str = "/Test"
}
var newFileName = str + '/Upload/' + path + "/" + timestamp1 + "" + suffix;
// var uploadMsg = {
// Bucket: "viitto-1301420277",
// Region: "ap-chengdu",
// /* 存储桶所在地域,必须字段 */
// SecretId: "AKIDDPnbIzi8C1eqEOPP8dw6MNAg9H9ldDKd",
// SecretKey: "PdcLtOjslUzNFYdU4OSI1fKtdHpFT2Ob",
// };
var uploadMsg = {
Bucket: upInfo.Bucket,
Region: upInfo.Region,
SecretId: upInfo.SecretId,
SecretKey: upInfo.SecretKey,
};
var COS = require('cos-js-sdk-v5');
var cos = new COS({
SecretId: uploadMsg.SecretId,
SecretKey: uploadMsg.SecretKey,
});
cos.putObject({
Bucket: uploadMsg.Bucket,
Region: uploadMsg.Region, //存储桶所在地域,必须字段
Key: newFileName, //文件名
StorageClass: 'STANDARD',
Body: fileObj, // 上传文件对象
onProgress: function (progressData) {}
}, function (err, data) {
if (data && data.statusCode == 200) {
var uploadResult = {
resultCode: 1,
FileName: fileObj.name,
FileUrl: "http://" + data.Location
}
if (callback) {
console.log(uploadResult,'uploadResult');
callback(uploadResult);
}
} else {
/*上传文件异常*/
console.log(err || data);
}
});
},
//上传至阿里云
Vue.prototype.uploadToAli = function (path, fileObj, successCall) {
var upInfo = JSON.parse(localStorage.uploadInfo);
var OSS = require('ali-oss');
var oss = new OSS({
region: upInfo.Region,
accessKeyId: upInfo.SecretId,
accessKeySecret: upInfo.SecretKey,
bucket: upInfo.Bucket
// region: 'oss-cn-chengdu',
// accessKeyId: 'LTAIwE7l9dImZSa3',
// accessKeySecret: 'j47Ajn0d0WzUCIX8Biyj3P2r8QDltI',
// bucket: 'vt-im-bucket'
})
let that = this;
let checkpoint = null;
let percentage = 0;
//获取文件扩展名
var filename = fileObj.name;
var index = filename.lastIndexOf(".");
......@@ -223,50 +316,17 @@ export default {
str = "/Test"
}
var newFileName = str + '/Upload/' + path + "/" + timestamp1 + "" + suffix;
// var uploadMsg = {
// Bucket: "viitto-1301420277",
// Region: "ap-chengdu",
// /* 存储桶所在地域,必须字段 */
// SecretId: "AKIDDPnbIzi8C1eqEOPP8dw6MNAg9H9ldDKd",
// SecretKey: "PdcLtOjslUzNFYdU4OSI1fKtdHpFT2Ob",
// };
var uploadMsg = {
Bucket: upInfo.Bucket,
Region: upInfo.Region,
SecretId: upInfo.SecretId,
SecretKey: upInfo.SecretKey,
};
var COS = require('cos-js-sdk-v5');
var cos = new COS({
SecretId: uploadMsg.SecretId,
SecretKey: uploadMsg.SecretKey,
});
cos.putObject({
Bucket: uploadMsg.Bucket,
Region: uploadMsg.Region, //存储桶所在地域,必须字段
Key: newFileName, //文件名
StorageClass: 'STANDARD',
Body: fileObj, // 上传文件对象
onProgress: function (progressData) {}
}, function (err, data) {
if (data && data.statusCode == 200) {
var uploadResult = {
resultCode: 1,
FileName: fileObj.name,
FileUrl: "http://" + data.Location
}
if (callback) {
callback(uploadResult);
}
} else {
/*上传文件异常*/
console.log(err || data);
// fileName = "/New" + '/' +path+ '/' + fileName + "." + files.name.split('.').pop()
var result = oss.multipartUpload(newFileName, fileObj, {
progress: function* (p) {}
}).then(res=>{
var uploadResult = {
resultCode: 1,
FileName: fileObj.name,
FileUrl: res.res.requestUrls[0]
}
});
}else{
this.Error('请先配置上传');
}
successCall(uploadResult);
})
},
//公用跳转
Vue.prototype.CommonJump = function (path, obj) {
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment