Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
X
xxx_phase2_web
Project overview
Project overview
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
夏敏伟
xxx_phase2_web
Commits
4beffbb2
Commit
4beffbb2
authored
Jul 18, 2024
by
以墨为白
🎧
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
前端直连下载文件
parent
07f0cf39
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
43 additions
and
1 deletion
+43
-1
src/util/http_util.js
src/util/http_util.js
+43
-1
No files found.
src/util/http_util.js
View file @
4beffbb2
...
...
@@ -819,6 +819,46 @@ let uploadOSSProgress = (filename, bucket, file, progressFunction) => {
});
});
};
/**
* 直连oss下载,数据较大时需要配合进度条使用
* @param {*} bucket
* @param {*} filename
* @param {*} originFileName
* @returns
*/
let
downloadOSS
=
(
bucket
,
filename
,
originFileName
)
=>
{
return
new
Promise
((
resolve
,
reject
)
=>
{
fetch
(
`api/rest/file/getDownloadUrl?bucket=
${
bucket
}
&filename=
${
filename
}
`
,
{
headers
:
new
Headers
(
addHeaders
({}))
}).
then
(
res
=>
{
if
(
res
.
status
==
200
)
{
return
res
.
json
();
}
else
{
console
.
log
(
res
.
statusText
);
reject
(
HTTP_STATUS
);
}
}).
then
(
res
=>
{
if
(
res
.
code
==
9000
)
{
return
fetch
(
res
.
data
,
{
method
:
"
GET
"
,
})
}
else
{
return
Promise
.
reject
({
err
:
res
.
message
});
}
}).
then
(
res
=>
res
.
blob
().
then
(
blob
=>
{
filename
=
originFileName
||
filename
;
let
a
=
document
.
createElement
(
'
a
'
);
let
url
=
window
.
URL
.
createObjectURL
(
blob
);
a
.
href
=
url
;
a
.
download
=
filename
;
a
.
click
();
window
.
URL
.
revokeObjectURL
(
url
);
resolve
(
res
.
data
);
})).
catch
(
err
=>
{
reject
(
err
);
});
});
}
//#endregion
//#region sse支持
...
...
@@ -967,5 +1007,7 @@ export {
httpSSERequestPoly
,
uploadOSS
,
uploadOSSProgress
,
fetchEventSource
fetchEventSource
,
downloadOSS
}
\ No newline at end of file
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