Skip to content

Commit d3fab9a

Browse files
committed
📖 CRM:code review 前端直接上传
1 parent ffeaa89 commit d3fab9a

File tree

3 files changed

+6
-6
lines changed

3 files changed

+6
-6
lines changed

.env.local

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ VITE_DEV=true
66
# 请求路径
77
VITE_BASE_URL='http://localhost:48080'
88

9-
# 文件上传类型:server - 后端上传, client - 前端直连上传,仅支持S3服务
9+
# 文件上传类型:server - 后端上传, client - 前端直连上传,仅支持 S3 服务
1010
VITE_UPLOAD_TYPE=server
1111
# 上传路径
1212
VITE_UPLOAD_URL='http://localhost:48080/admin-api/infra/file/upload'

src/api/infra/file/index.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,10 +27,10 @@ export const deleteFile = (id: number) => {
2727
}
2828

2929
// 获取文件预签名地址
30-
export const getFilePresignedUrl = (fileName: string) => {
30+
export const getFilePresignedUrl = (path: string) => {
3131
return request.get<FilePresignedUrlRespVO>({
3232
url: '/infra/file/presigned-url',
33-
params: { fileName }
33+
params: { path }
3434
})
3535
}
3636

src/components/UploadFile/src/useUpload.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -18,9 +18,9 @@ export const useUpload = () => {
1818
const fileName = await generateFileName(options.file)
1919
// 1.2 获取文件预签名地址
2020
const presignedInfo = await FileApi.getFilePresignedUrl(fileName)
21-
// 1.3 上传文件(不能使用ElUpload的ajaxUpload方法的原因:其使用的是FormData上传,Minio不支持
21+
// 1.3 上传文件(不能使用 ElUpload 的 ajaxUpload 方法的原因:其使用的是 FormData 上传,Minio 不支持
2222
return axios.put(presignedInfo.uploadUrl, options.file).then(() => {
23-
// 1.4. 记录文件信息到后端
23+
// 1.4. 记录文件信息到后端(异步)
2424
createFile(presignedInfo, fileName, options.file)
2525
// 通知成功,数据格式保持与后端上传的返回结果一致
2626
return { data: presignedInfo.url }
@@ -29,7 +29,7 @@ export const useUpload = () => {
2929
// 模式二:后端上传(需要增加后端身份认证请求头)
3030
options.headers['Authorization'] = 'Bearer ' + getAccessToken()
3131
options.headers['tenant-id'] = getTenantId()
32-
// 使用ElUpload的上传方法
32+
// 使用 ElUpload 的上传方法
3333
return ajaxUpload(options)
3434
}
3535
}

0 commit comments

Comments
 (0)