Skip to content
Toggle navigation
P
Projects
G
Groups
S
Snippets
Help
phsl
/
admin
This project
Loading...
Sign in
Toggle navigation
Go to a project
Project
Repository
Issues
0
Merge Requests
0
Pipelines
Wiki
Snippets
Members
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Commit
89fdb5ce
authored
Feb 04, 2024
by
owen
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
基础设施:前端直连上传,优先使用自定义域名
parent
dd08fbcb
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
10 additions
and
10 deletions
+10
-10
src/api/infra/file/index.ts
+3
-1
src/components/UploadFile/src/useUpload.ts
+7
-9
No files found.
src/api/infra/file/index.ts
View file @
89fdb5ce
...
@@ -10,7 +10,9 @@ export interface FilePageReqVO extends PageParam {
...
@@ -10,7 +10,9 @@ export interface FilePageReqVO extends PageParam {
export
interface
FilePresignedUrlRespVO
{
export
interface
FilePresignedUrlRespVO
{
// 文件配置编号
// 文件配置编号
configId
:
number
configId
:
number
// 文件预签名地址
// 文件上传 URL
uploadUrl
:
string
// 文件 URL
url
:
string
url
:
string
}
}
...
...
src/components/UploadFile/src/useUpload.ts
View file @
89fdb5ce
...
@@ -19,11 +19,11 @@ export const useUpload = () => {
...
@@ -19,11 +19,11 @@ export const useUpload = () => {
// 1.2 获取文件预签名地址
// 1.2 获取文件预签名地址
const
presignedInfo
=
await
FileApi
.
getFilePresignedUrl
(
fileName
)
const
presignedInfo
=
await
FileApi
.
getFilePresignedUrl
(
fileName
)
// 1.3 上传文件(不能使用ElUpload的ajaxUpload方法的原因:其使用的是FormData上传,Minio不支持)
// 1.3 上传文件(不能使用ElUpload的ajaxUpload方法的原因:其使用的是FormData上传,Minio不支持)
return
axios
.
put
(
presignedInfo
.
url
,
options
.
file
).
then
(()
=>
{
return
axios
.
put
(
presignedInfo
.
u
ploadU
rl
,
options
.
file
).
then
(()
=>
{
// 1.4. 记录文件信息到后端
// 1.4. 记录文件信息到后端
c
onst
fileVo
=
createFile
(
presignedInfo
.
configId
,
fileName
,
presignedInfo
.
url
,
options
.
file
)
c
reateFile
(
presignedInfo
,
fileName
,
options
.
file
)
// 通知成功,数据格式保持与后端上传的返回结果一致
// 通知成功,数据格式保持与后端上传的返回结果一致
return
{
data
:
fileV
o
.
url
}
return
{
data
:
presignedInf
o
.
url
}
})
})
}
else
{
}
else
{
// 模式二:后端上传(需要增加后端身份认证请求头)
// 模式二:后端上传(需要增加后端身份认证请求头)
...
@@ -42,17 +42,15 @@ export const useUpload = () => {
...
@@ -42,17 +42,15 @@ export const useUpload = () => {
/**
/**
* 创建文件信息
* 创建文件信息
* @param
configId 文件配置编号
* @param
vo 文件预签名信息
* @param name 文件名称
* @param name 文件名称
* @param url 文件地址
* @param file 文件
* @param file 文件
*/
*/
function
createFile
(
configId
:
number
,
name
:
string
,
url
:
string
,
file
:
UploadRawFile
)
{
function
createFile
(
vo
:
FileApi
.
FilePresignedUrlRespVO
,
name
:
string
,
file
:
UploadRawFile
)
{
const
fileVo
=
{
const
fileVo
=
{
configId
:
configId
,
configId
:
vo
.
configId
,
url
:
vo
.
url
,
path
:
name
,
path
:
name
,
// 移除预签名参数:参数只在上传时有用,查看时不需要
url
:
url
.
substring
(
0
,
url
.
indexOf
(
'?'
)),
name
:
file
.
name
,
name
:
file
.
name
,
type
:
file
.
type
,
type
:
file
.
type
,
size
:
file
.
size
size
:
file
.
size
...
...
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