基础设施:前端直连上传,优先使用自定义域名

(cherry picked from commit 89fdb5ced9)
This commit is contained in:
owen 2024-02-04 20:57:05 +08:00 committed by shizhong
parent e2a9835a5f
commit 818dc4d8e3
2 changed files with 10 additions and 10 deletions

View File

@ -10,7 +10,9 @@ export interface FilePageReqVO extends PageParam {
export interface FilePresignedUrlRespVO {
// 文件配置编号
configId: number
// 文件预签名地址
// 文件上传 URL
uploadUrl: string
// 文件 URL
url: string
}

View File

@ -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