Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
X
xiaomai-cloud-class-web
Overview
Overview
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
1
Merge Requests
1
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
xiaomai-cloud-class
xiaomai-cloud-class-web
Commits
741ac6dd
Commit
741ac6dd
authored
Feb 03, 2026
by
renmanyi
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
feat:上传业务改造
parent
0e333b1d
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
46 additions
and
84 deletions
+46
-84
src/core/upload.js
+46
-84
No files found.
src/core/upload.js
View file @
741ac6dd
...
...
@@ -5,8 +5,8 @@ import { message } from 'antd';
/*
* @Author: 吴文洁
* @Date: 2020-08-11 11:47:14
* @LastEditors:
wufan
* @LastEditTime: 202
1-01-03 21:04:30
* @LastEditors:
renmanyi
* @LastEditTime: 202
6-02-03 14:29:56
* @Description:
* @Copyright: 杭州杰竞科技有限公司 版权所有
*/
...
...
@@ -22,73 +22,29 @@ class Upload {
return
Service
.
Hades
(
'public/hades/commonOssAuthority'
,
param
).
then
((
res
)
=>
{
const
signInfo
=
res
.
result
;
const
{
fileUrl
}
=
res
.
result
return
this
.
uploadBlobToNewOSS
(
Blob
,
name
,
dir
,
signInfo
.
signatureVO
||
signInfo
).
then
(()
=>
{
console
.
log
(
'url2222222'
,
fileUrl
);
return
dataType
===
'url'
?
fileUrl
:
signInfo
});
if
(
signInfo
.
vendorType
===
'TENCENT_COS'
)
{
return
this
.
uploadBlobToNewOSSTx
(
Blob
,
name
,
signInfo
.
signatureVO
||
signInfo
).
then
(()
=>
{
return
dataType
===
'url'
?
fileUrl
:
signInfo
})
}
else
{
return
this
.
uploadBlobToNewOSS
(
Blob
,
name
,
signInfo
.
signatureVO
||
signInfo
).
then
(()
=>
{
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
{
complete
((
result
.
url
||
false
).
replace
(
/http:/
,
"https:"
));
}
};
xhr
.
send
(
fd
);
};
xhr
.
onerror
=
()
=>
{
complete
(
false
);
}
xhr
.
send
(
null
);
return
xhr
;
}
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
;
})
}
// mfs上传文件
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
)
{
static
uploadBlobToNewOSS
(
Blob
,
name
,
signInfo
)
{
return
new
Promise
(
function
(
resolve
,
reject
)
{
var
xhr
=
new
XMLHttpRequest
();
var
fd
=
new
FormData
();
...
...
@@ -102,6 +58,9 @@ class Upload {
// dir = Blob.type == 'text/html' ? 'html/' : '';
// }
fd
.
append
(
'key'
,
signInfo
.
key
);
if
(
signInfo
.
securityToken
)
{
fd
.
append
(
"x-oss-security-token"
,
signInfo
.
securityToken
);
}
fd
.
append
(
'file'
,
Blob
);
fd
.
append
(
'success_action_status'
,
200
);
xhr
.
open
(
'POST'
,
signInfo
.
host
.
replace
(
/http:/
,
"https:"
),
true
);
...
...
@@ -119,33 +78,36 @@ class Upload {
};
// 监听多媒体上传进度
static
uploadToOSSEvent
(
Blob
,
name
,
onInit
=
()
=>
{},
onProgress
=
()
=>
{},
onLoad
=
()
=>
{},
onError
=
()
=>
{})
{
Service
.
MFS
(
'anon/mfs/webTokenWithAccessUrl'
,
{
resourceName
:
name
,
instId
:
(
!!
window
.
currentUserInstInfo
&&
window
.
currentUserInstInfo
.
instId
)
||
LS
.
get
(
'instId'
)
||
''
}).
then
((
res
)
=>
{
const
signInfo
=
res
.
result
;
const
{
url
}
=
res
.
result
;
const
xhr
=
new
XMLHttpRequest
();
const
fd
=
new
FormData
();
fd
.
append
(
'OSSAccessKeyId'
,
signInfo
.
accessId
);
static
uploadBlobToNewOSSTx
(
Blob
,
name
,
signInfo
=
{})
{
return
new
Promise
(
function
(
resolve
,
reject
)
{
var
xhr
=
new
XMLHttpRequest
();
var
fd
=
new
FormData
();
let
timeVal
=
JSON
.
parse
(
signInfo
.
extAttrs
)[
'q-key-time'
];
fd
.
append
(
'q-sign-algorithm'
,
'sha1'
);
fd
.
append
(
'key'
,
signInfo
.
key
);
fd
.
append
(
'q-ak'
,
signInfo
.
accessKeyId
);
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
(
'expire'
,
signInfo
.
expire
);
fd
.
append
(
'signature'
,
signInfo
.
signature
);
fd
.
append
(
'key'
,
signInfo
.
key
);
fd
.
append
(
'file'
,
Blob
);
fd
.
append
(
'success_action_status'
,
200
);
onInit
(
url
,
xhr
,
signInfo
)
xhr
.
open
(
'POST'
,
signInfo
.
host
);
xhr
.
upload
.
addEventListener
(
"progress"
,
onProgress
,
false
);
xhr
.
onload
=
onLoad
;
xhr
.
onerror
=
onError
;
xhr
.
open
(
'POST'
,
signInfo
.
host
,
true
);
xhr
.
onload
=
()
=>
{
if
(
xhr
.
readyState
===
4
)
{
if
(
xhr
.
status
===
200
)
{
const
res
=
JSON
.
parse
(
xhr
.
responseText
);
resolve
(
res
.
result
.
url
);
}
else
{
console
.
error
(
'Error: '
+
xhr
.
status
);
}
}
};
xhr
.
send
(
fd
);
})
}
})
;
}
;
static
uploadTextToOSS
(
string
,
name
,
success
,
error
)
{
if
(
!
string
)
return
success
();
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment