Commit be8e13eb authored by 黄奎's avatar 黄奎

阿里文件上传修改

parent e36010bb
...@@ -55,10 +55,10 @@ export default { ...@@ -55,10 +55,10 @@ export default {
//域名管理对象 //域名管理对象
Vue.prototype.domainManager = function () { Vue.prototype.domainManager = function () {
let domainUrl = "http://192.168.10.68:5000"; let domainUrl = "http://192.168.10.68:5000";
// let domainUrl = "https://mallapi.oytour.com"; domainUrl = "https://mallapi.oytour.com";
let javaUrl = 'http://192.168.10.214:8018'; let javaUrl = 'http://192.168.10.214:8018';
let vtUploadUrl = "http://192.168.10.214:8120"; let vtUploadUrl = "http://192.168.5.46:8120";
let vtViewUrl = "http://192.168.10.214:8130"; let vtViewUrl = "http://192.168.5.46:8130";
let locationName = window.location.hostname; let locationName = window.location.hostname;
if (locationName.indexOf('testmall.oytour') !== -1) { if (locationName.indexOf('testmall.oytour') !== -1) {
...@@ -285,36 +285,34 @@ export default { ...@@ -285,36 +285,34 @@ export default {
} }
}); });
}, },
//上传至阿里云 //上传至阿里云【2024-05-20转为后台上传】
Vue.prototype.uploadToAli = function (path, fileObj, successCall) { Vue.prototype.uploadToAli = function (path, fileObj, successCall) {
var upInfo = JSON.parse(localStorage.uploadInfo); var that = this;
var OSS = require('ali-oss');
var oss = new OSS({
region: upInfo.Region,
accessKeyId: upInfo.SecretId,
accessKeySecret: upInfo.SecretKey,
bucket: upInfo.Bucket
})
//获取文件扩展名
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 = ''; let str = '';
if (this.isOnline()) { if (this.isOnline()) {
str = "/Test" str = "/2024"
} }
var newFileName = str + '/Upload/' + path + "/" + timestamp1 + "" + suffix; var newFileName = str + '/Upload/' + path + "/";
var result = oss.multipartUpload(newFileName, fileObj, { var uploadUrl = that.domainManager().VTUploadUrl + "/Upload/UploadToALiOSS?filePath=" + newFileName;
progress: function* (p) {} var formData = new FormData();
}).then(res => { formData.append("myfile", fileObj);
that.$http.post(uploadUrl, formData, {})
.then(res => {
console.log("ali_res", res);
if (res && res.data.StatusCode == 1 && res.data.FilePath) {
var uploadResult = { var uploadResult = {
resultCode: 1, resultCode: 1,
FileName: fileObj.name, FileName: fileObj.name,
FileUrl: res.res.requestUrls[0].replace('http', 'https') FileUrl:res.data.FilePath,
VideoCoverImg: that.domainManager().VTViewUrl + res.data.VideoCoverImg
} }
if (successCall) {
successCall(uploadResult); successCall(uploadResult);
}) }
}
}).catch(function (reason) {
console.log(reason)
});
}, },
//公用跳转 //公用跳转
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