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
d3fab9a0
authored
Feb 17, 2024
by
YunaiV
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
📖
CRM:code review 前端直接上传
parent
ffeaa891
Show whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
6 additions
and
6 deletions
+6
-6
.env.local
+1
-1
src/api/infra/file/index.ts
+2
-2
src/components/UploadFile/src/useUpload.ts
+3
-3
No files found.
.env.local
View file @
d3fab9a0
...
...
@@ -6,7 +6,7 @@ VITE_DEV=true
# 请求路径
VITE_BASE_URL='http://localhost:48080'
# 文件上传类型:server - 后端上传, client - 前端直连上传,仅支持
S3
服务
# 文件上传类型:server - 后端上传, client - 前端直连上传,仅支持
S3
服务
VITE_UPLOAD_TYPE=server
# 上传路径
VITE_UPLOAD_URL='http://localhost:48080/admin-api/infra/file/upload'
...
...
src/api/infra/file/index.ts
View file @
d3fab9a0
...
...
@@ -27,10 +27,10 @@ export const deleteFile = (id: number) => {
}
// 获取文件预签名地址
export
const
getFilePresignedUrl
=
(
fileName
:
string
)
=>
{
export
const
getFilePresignedUrl
=
(
path
:
string
)
=>
{
return
request
.
get
<
FilePresignedUrlRespVO
>
({
url
:
'/infra/file/presigned-url'
,
params
:
{
fileName
}
params
:
{
path
}
})
}
...
...
src/components/UploadFile/src/useUpload.ts
View file @
d3fab9a0
...
...
@@ -18,9 +18,9 @@ export const useUpload = () => {
const
fileName
=
await
generateFileName
(
options
.
file
)
// 1.2 获取文件预签名地址
const
presignedInfo
=
await
FileApi
.
getFilePresignedUrl
(
fileName
)
// 1.3 上传文件(不能使用
ElUpload的ajaxUpload方法的原因:其使用的是FormData上传,Minio
不支持)
// 1.3 上传文件(不能使用
ElUpload 的 ajaxUpload 方法的原因:其使用的是 FormData 上传,Minio
不支持)
return
axios
.
put
(
presignedInfo
.
uploadUrl
,
options
.
file
).
then
(()
=>
{
// 1.4. 记录文件信息到后端
// 1.4. 记录文件信息到后端
(异步)
createFile
(
presignedInfo
,
fileName
,
options
.
file
)
// 通知成功,数据格式保持与后端上传的返回结果一致
return
{
data
:
presignedInfo
.
url
}
...
...
@@ -29,7 +29,7 @@ export const useUpload = () => {
// 模式二:后端上传(需要增加后端身份认证请求头)
options
.
headers
[
'Authorization'
]
=
'Bearer '
+
getAccessToken
()
options
.
headers
[
'tenant-id'
]
=
getTenantId
()
// 使用
ElUpload
的上传方法
// 使用
ElUpload
的上传方法
return
ajaxUpload
(
options
)
}
}
...
...
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