Commit 025935b3 authored by zhengke's avatar zhengke

增加阿里云上传

parent 164522a7
...@@ -58,8 +58,8 @@ export default { ...@@ -58,8 +58,8 @@ export default {
let javaUrl = 'http://192.168.2.65:8018'; let javaUrl = 'http://192.168.2.65:8018';
// domainUrl = "http://192.168.1.27:8200"; // domainUrl = "http://192.168.1.27:8200";
domainUrl = "http://192.168.1.5:8088"; //domainUrl = "http://192.168.1.13:8088";
//domainUrl = "http://192.168.1.21"; domainUrl = "http://192.168.1.21";
//domainUrl = "https://localhost:5001"; //domainUrl = "https://localhost:5001";
let vtUploadUrl = "http://192.168.1.214:8120"; let vtUploadUrl = "http://192.168.1.214:8120";
...@@ -181,6 +181,7 @@ export default { ...@@ -181,6 +181,7 @@ export default {
//上传文件到云存储 //上传文件到云存储
Vue.prototype.UploadFileToTencent = function (path, fileObj, callback) { Vue.prototype.UploadFileToTencent = function (path, fileObj, callback) {
// debugger; // debugger;
var upInfo = JSON.parse(localStorage.uploadInfo);
if (fileObj.type == "image/png" || fileObj.type == "image/jpeg") { if (fileObj.type == "image/png" || fileObj.type == "image/jpeg") {
let that = this let that = this
lrz(fileObj, { lrz(fileObj, {
...@@ -200,19 +201,40 @@ export default { ...@@ -200,19 +201,40 @@ export default {
var newFile = new File([u8arr], fileObj.name, { var newFile = new File([u8arr], fileObj.name, {
type: mime type: mime
}); });
if(upInfo.IsDefault==1){
that.uploadStart(path, newFile, callback) that.uploadStart(path, newFile, callback)
}else{
this.Error('请先配置上传');
}
}).catch(function (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 () { }).always(function () {
//不管成功或失败,都会执行 //不管成功或失败,都会执行
}) })
}else{ }else{
if(upInfo.IsDefault==1){
if(upInfo.StoreType==1){
this.uploadStart(path, fileObj, callback) this.uploadStart(path, fileObj, callback)
} }
if(upInfo.StoreType==3){
this.uploadToAli(path, fileObj, callback)
}
}else{
this.Error('请先配置上传');
}
}
}, },
Vue.prototype.uploadStart = function (path, fileObj, callback) { Vue.prototype.uploadStart = function (path, fileObj, callback) {
var upInfo = JSON.parse(localStorage.uploadInfo); var upInfo = JSON.parse(localStorage.uploadInfo);
if(upInfo.IsDefault==1){
//获取文件扩展名 //获取文件扩展名
var filename = fileObj.name; var filename = fileObj.name;
var index = filename.lastIndexOf("."); var index = filename.lastIndexOf(".");
...@@ -257,6 +279,7 @@ export default { ...@@ -257,6 +279,7 @@ export default {
FileUrl: "http://" + data.Location FileUrl: "http://" + data.Location
} }
if (callback) { if (callback) {
console.log(uploadResult,'uploadResult');
callback(uploadResult); callback(uploadResult);
} }
} else { } else {
...@@ -264,9 +287,46 @@ export default { ...@@ -264,9 +287,46 @@ export default {
console.log(err || data); console.log(err || data);
} }
}); });
}else{ },
this.Error('请先配置上传'); //上传至阿里云
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(".");
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;
// 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]
}
successCall(uploadResult);
})
}, },
//公用跳转 //公用跳转
Vue.prototype.CommonJump = function (path, obj) { 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