|
|
@@ -12,7 +12,7 @@
|
|
|
* @param {area} 地区
|
|
|
* @return {string|boolean} 成功返回文件地址,失败返回false
|
|
|
*/
|
|
|
-import COS from "./cos-wx-sdk-v5.min"
|
|
|
+import COS from "cos-js-sdk-v5"
|
|
|
|
|
|
console.log(COS)
|
|
|
import tools from "./tools";
|
|
|
@@ -26,17 +26,27 @@ let Region = 'ap-guangzhou';
|
|
|
|
|
|
let cos=null;
|
|
|
function startCos(){
|
|
|
+ console.log('startCos-----------------')
|
|
|
cos = new COS({
|
|
|
getAuthorization: function (options, callback) {
|
|
|
console.log('---------------获取初始化信息')
|
|
|
+
|
|
|
getTxySts().then((res)=>{
|
|
|
+ console.log({
|
|
|
+ TmpSecretId: res.data.credentials.tmpSecretId,
|
|
|
+ TmpSecretKey: res.data.credentials.tmpSecretKey,
|
|
|
+ XCosSecurityToken: res.data.credentials.sessionToken,
|
|
|
+ StartTime: res.data.startTime, // 时间戳,单位秒,如:1580000000,建议返回服务器时间作为签名的开始时间,避免用户浏览器本地时间偏差过大导致签名错误
|
|
|
+ ExpiredTime: res.data.expiredTime, // 时间戳,单位秒,如:1580000900
|
|
|
+ })
|
|
|
+ console.log('---------------获取初始化信息')
|
|
|
if(res.code===0){
|
|
|
callback({
|
|
|
TmpSecretId: res.data.credentials.tmpSecretId,
|
|
|
TmpSecretKey: res.data.credentials.tmpSecretKey,
|
|
|
XCosSecurityToken: res.data.credentials.sessionToken,
|
|
|
- StartTime: res.data.startTime, // 时间戳,单位秒,如:1580000000,建议返回服务器时间作为签名的开始时间,避免用户浏览器本地时间偏差过大导致签名错误
|
|
|
- ExpiredTime: res.data.expiredTime, // 时间戳,单位秒,如:1580000900
|
|
|
+ StartTime: res.data.startTime*1, // 时间戳,单位秒,如:1580000000,建议返回服务器时间作为签名的开始时间,避免用户浏览器本地时间偏差过大导致签名错误
|
|
|
+ ExpiredTime: res.data.expiredTime*1, // 时间戳,单位秒,如:1580000900
|
|
|
})
|
|
|
}
|
|
|
})
|
|
|
@@ -63,13 +73,13 @@ function txUploadFile(file,folder){
|
|
|
return new Promise((resolve, reject) => {
|
|
|
console.log('cos-*-------------------------',cos)
|
|
|
console.log(file)
|
|
|
- console.log(folder+'/'+tools.getDate()+tools.getRandFileName(file))
|
|
|
+ console.log(folder+'/'+tools.getDate()+tools.getRandFileName(file.name))
|
|
|
// 分片上传文件
|
|
|
- cos.postObject({
|
|
|
+ cos.putObject({
|
|
|
Bucket: Bucket,
|
|
|
Region: Region,
|
|
|
- Key: folder+'/'+tools.getDate()+'/'+tools.getRandFileName(file),
|
|
|
- FilePath: file,
|
|
|
+ Key: folder+'/'+tools.getDate()+'/'+tools.getRandFileName(file.name),
|
|
|
+ Body: file,
|
|
|
onHashProgress: function (progressData) {
|
|
|
console.log('校验中', JSON.stringify(progressData));
|
|
|
},
|
|
|
@@ -78,7 +88,8 @@ function txUploadFile(file,folder){
|
|
|
},
|
|
|
}, function (err, data) {
|
|
|
tools.hideLoading()
|
|
|
- console.log(err, data);
|
|
|
+ console.log(err);
|
|
|
+ console.log(data);
|
|
|
if(data.Location!==undefined){
|
|
|
data.Location='https://'+data.Location;
|
|
|
resolve( data)
|