Commit 741ac6dd by renmanyi

feat:上传业务改造

parent 0e333b1d
...@@ -5,8 +5,8 @@ import { message } from 'antd'; ...@@ -5,8 +5,8 @@ import { message } from 'antd';
/* /*
* @Author: 吴文洁 * @Author: 吴文洁
* @Date: 2020-08-11 11:47:14 * @Date: 2020-08-11 11:47:14
* @LastEditors: wufan * @LastEditors: renmanyi
* @LastEditTime: 2021-01-03 21:04:30 * @LastEditTime: 2026-02-03 14:29:56
* @Description: * @Description:
* @Copyright: 杭州杰竞科技有限公司 版权所有 * @Copyright: 杭州杰竞科技有限公司 版权所有
*/ */
...@@ -22,73 +22,29 @@ class Upload { ...@@ -22,73 +22,29 @@ class Upload {
return Service.Hades('public/hades/commonOssAuthority', param).then((res) => { return Service.Hades('public/hades/commonOssAuthority', param).then((res) => {
const signInfo = res.result; const signInfo = res.result;
const { fileUrl } = res.result const { fileUrl } = res.result
return this.uploadBlobToNewOSS(Blob, name, dir, signInfo.signatureVO || signInfo).then(() => { if (signInfo.vendorType === 'TENCENT_COS') {
console.log('url2222222',fileUrl); return this.uploadBlobToNewOSSTx(Blob, name, signInfo.signatureVO || signInfo).then(() => {
return dataType === 'url' ? fileUrl : signInfo return dataType === 'url' ? fileUrl : signInfo
});
}) })
};
static asyncUploadVideoToOSS(Blob, name, complete, dir, needSize) {
name = window.encodeURI(name.toLowerCase());
let ossSignServerAddress = UPLOAD + 'xm/oss/web/token?bucket=v';
const xhr = new XMLHttpRequest();
xhr.open('GET', ossSignServerAddress, true);
xhr.onload = () => {
const signInfo = JSON.parse(xhr.responseText);
const fd = new FormData();
fd.append('Filename', name);
fd.append('callback', signInfo.callback);
fd.append('expire', signInfo.expire);
fd.append('policy', signInfo.policy);
fd.append('signature', signInfo.signature);
fd.append('OSSAccessKeyId', signInfo.accessid);
fd.append('success_action_status', 200);
if (!dir) {
dir = Blob.type == 'text/html' ? 'html/' : '';
}
fd.append('key', signInfo.dir + dir + name);
fd.append('file', Blob);
xhr.open('POST', signInfo.host, true);
xhr.onload = () => {
const result = JSON.parse(xhr.responseText);
if (needSize) {
complete(result);
} else { } else {
complete((result.url || false).replace(/http:/, "https:")); return this.uploadBlobToNewOSS(
Blob,
name,
signInfo.signatureVO || signInfo
).then(() => {
return dataType === 'url' ? fileUrl : signInfo
});
} }
})
}; };
xhr.send(fd);
};
xhr.onerror = () => {
complete(false);
}
xhr.send(null);
return xhr;
}
static getVideoParseRoute(videoUrl) { static getVideoParseRoute(videoUrl) {
return Service.MFS('anon/video/parse', { videoUrl }).then((res) => { return Service.Sales('anon/resource/parseVideo', { videoUrl }).then((res) => {
return res.result.sdUrl || videoUrl; return res.result.sdUrl || videoUrl;
}) })
} }
// mfs上传文件 static uploadBlobToNewOSS(Blob, name, signInfo) {
static uploadBlobToMFSOSS(signInfoUrl, signInfoParams, Blob, name, dir) {
return Service.post(signInfoUrl, signInfoParams).then(res => {
var signInfo = res.result;
return this.uploadBlobToNewOSS(Blob, name, dir, signInfo.signatureVO || signInfo).then((res) => {
return signInfo;
});
})
}
static uploadBlobToNewOSS(Blob, name, dir, signInfo) {
return new Promise(function (resolve, reject) { return new Promise(function (resolve, reject) {
var xhr = new XMLHttpRequest(); var xhr = new XMLHttpRequest();
var fd = new FormData(); var fd = new FormData();
...@@ -102,6 +58,9 @@ class Upload { ...@@ -102,6 +58,9 @@ class Upload {
// dir = Blob.type == 'text/html' ? 'html/' : ''; // dir = Blob.type == 'text/html' ? 'html/' : '';
// } // }
fd.append('key', signInfo.key); fd.append('key', signInfo.key);
if(signInfo.securityToken) {
fd.append("x-oss-security-token", signInfo.securityToken);
}
fd.append('file', Blob); fd.append('file', Blob);
fd.append('success_action_status', 200); fd.append('success_action_status', 200);
xhr.open('POST', signInfo.host.replace(/http:/, "https:"), true); xhr.open('POST', signInfo.host.replace(/http:/, "https:"), true);
...@@ -119,33 +78,36 @@ class Upload { ...@@ -119,33 +78,36 @@ class Upload {
}; };
static uploadBlobToNewOSSTx(Blob, name, signInfo={}) {
// 监听多媒体上传进度 return new Promise(function (resolve, reject) {
static uploadToOSSEvent(Blob, name, onInit=()=>{}, onProgress=()=>{}, onLoad=()=>{}, onError=()=>{}) { var xhr = new XMLHttpRequest();
Service.MFS('anon/mfs/webTokenWithAccessUrl', { resourceName: name, instId: (!!window.currentUserInstInfo && window.currentUserInstInfo.instId) || LS.get('instId') || '' }).then((res) => { var fd = new FormData();
const signInfo = res.result; let timeVal = JSON.parse(signInfo.extAttrs)['q-key-time'];
const { url } = res.result; fd.append('q-sign-algorithm', 'sha1');
const xhr = new XMLHttpRequest(); fd.append('key', signInfo.key);
const fd = new FormData(); fd.append('q-ak', signInfo.accessKeyId);
fd.append('OSSAccessKeyId', signInfo.accessId);
fd.append('policy', signInfo.policy); fd.append('policy', signInfo.policy);
fd.append('callback', signInfo.callback); fd.append('q-signature', signInfo.signature);
fd.append('success_action_status', '200');
fd.append('x-cos-callback', signInfo.callback);
signInfo.securityToken && fd.append("x-cos-security-token", signInfo.securityToken);
fd.append('q-key-time', timeVal);
fd.append('Filename', name); fd.append('Filename', name);
fd.append('expire', signInfo.expire);
fd.append('signature', signInfo.signature);
fd.append('key', signInfo.key);
fd.append('file', Blob); fd.append('file', Blob);
fd.append('success_action_status', 200); xhr.open('POST', signInfo.host, true);
xhr.onload = () => {
onInit(url,xhr,signInfo) if (xhr.readyState === 4) {
xhr.open('POST', signInfo.host); if (xhr.status === 200) {
xhr.upload.addEventListener("progress", onProgress, false); const res = JSON.parse(xhr.responseText);
xhr.onload = onLoad; resolve(res.result.url);
xhr.onerror = onError; } else {
xhr.send(fd); console.error('Error: ' + xhr.status);
})
} }
}
};
xhr.send(fd);
});
};
static uploadTextToOSS(string, name, success, error) { static uploadTextToOSS(string, name, success, error) {
if (!string) return success(); if (!string) return success();
......
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