From 818dc4d8e37edcd8f6ba713f4c7f7e0220f94376 Mon Sep 17 00:00:00 2001 From: owen Date: Sun, 4 Feb 2024 20:57:05 +0800 Subject: [PATCH] =?UTF-8?q?=E5=9F=BA=E7=A1=80=E8=AE=BE=E6=96=BD=EF=BC=9A?= =?UTF-8?q?=E5=89=8D=E7=AB=AF=E7=9B=B4=E8=BF=9E=E4=B8=8A=E4=BC=A0=EF=BC=8C?= =?UTF-8?q?=E4=BC=98=E5=85=88=E4=BD=BF=E7=94=A8=E8=87=AA=E5=AE=9A=E4=B9=89?= =?UTF-8?q?=E5=9F=9F=E5=90=8D?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit (cherry picked from commit 89fdb5ced9a8fdcef1a066f7b14071541dda1eb0) --- src/api/infra/file/index.ts | 4 +++- src/components/UploadFile/src/useUpload.ts | 16 +++++++--------- 2 files changed, 10 insertions(+), 10 deletions(-) diff --git a/src/api/infra/file/index.ts b/src/api/infra/file/index.ts index 7f543745..503711f6 100644 --- a/src/api/infra/file/index.ts +++ b/src/api/infra/file/index.ts @@ -10,7 +10,9 @@ export interface FilePageReqVO extends PageParam { export interface FilePresignedUrlRespVO { // 文件配置编号 configId: number - // 文件预签名地址 + // 文件上传 URL + uploadUrl: string + // 文件 URL url: string } diff --git a/src/components/UploadFile/src/useUpload.ts b/src/components/UploadFile/src/useUpload.ts index bee0d584..ecaecbde 100644 --- a/src/components/UploadFile/src/useUpload.ts +++ b/src/components/UploadFile/src/useUpload.ts @@ -19,11 +19,11 @@ export const useUpload = () => { // 1.2 获取文件预签名地址 const presignedInfo = await FileApi.getFilePresignedUrl(fileName) // 1.3 上传文件(不能使用ElUpload的ajaxUpload方法的原因:其使用的是FormData上传,Minio不支持) - return axios.put(presignedInfo.url, options.file).then(() => { + return axios.put(presignedInfo.uploadUrl, options.file).then(() => { // 1.4. 记录文件信息到后端 - const fileVo = createFile(presignedInfo.configId, fileName, presignedInfo.url, options.file) + createFile(presignedInfo, fileName, options.file) // 通知成功,数据格式保持与后端上传的返回结果一致 - return { data: fileVo.url } + return { data: presignedInfo.url } }) } else { // 模式二:后端上传(需要增加后端身份认证请求头) @@ -42,17 +42,15 @@ export const useUpload = () => { /** * 创建文件信息 - * @param configId 文件配置编号 + * @param vo 文件预签名信息 * @param name 文件名称 - * @param url 文件地址 * @param file 文件 */ -function createFile(configId: number, name: string, url: string, file: UploadRawFile) { +function createFile(vo: FileApi.FilePresignedUrlRespVO, name: string, file: UploadRawFile) { const fileVo = { - configId: configId, + configId: vo.configId, + url: vo.url, path: name, - // 移除预签名参数:参数只在上传时有用,查看时不需要 - url: url.substring(0, url.indexOf('?')), name: file.name, type: file.type, size: file.size