功能:支持全站分片上传
This commit is contained in:
@@ -1,4 +1,4 @@
|
||||
import axios, { AxiosError } from 'axios'
|
||||
import axios, { AxiosError, type AxiosProgressEvent } from 'axios'
|
||||
import router from '../router'
|
||||
import { message } from 'ant-design-vue'
|
||||
import { ADMIN_API_BASE_URL } from '../config/api'
|
||||
@@ -207,6 +207,21 @@ export interface ObjectStorageFileVO {
|
||||
createTime: string
|
||||
}
|
||||
|
||||
export interface ChunkUploadInitRequest {
|
||||
fileName: string
|
||||
fileSize: number
|
||||
contentType: string
|
||||
fileFingerprint: string
|
||||
scene: string
|
||||
}
|
||||
|
||||
export interface ChunkUploadSessionVO {
|
||||
uploadId: string
|
||||
chunkSize: number
|
||||
totalChunks: number
|
||||
uploadedChunks: number[]
|
||||
}
|
||||
|
||||
export const adminFileApi = {
|
||||
uploadFile: (file: File) => {
|
||||
const formData = new FormData()
|
||||
@@ -217,6 +232,32 @@ export const adminFileApi = {
|
||||
}
|
||||
})
|
||||
},
|
||||
initChunkUpload: (data: ChunkUploadInitRequest) => {
|
||||
return adminApi.post<ChunkUploadSessionVO>('/object-storage-file/upload/init', data) as unknown as Promise<ChunkUploadSessionVO>
|
||||
},
|
||||
uploadChunk: (
|
||||
data: { uploadId: string; chunkIndex: number; totalChunks: number; chunk: Blob },
|
||||
config?: { signal?: AbortSignal; onUploadProgress?: (event: AxiosProgressEvent) => void }
|
||||
) => {
|
||||
const formData = new FormData()
|
||||
formData.append('uploadId', data.uploadId)
|
||||
formData.append('chunkIndex', String(data.chunkIndex))
|
||||
formData.append('totalChunks', String(data.totalChunks))
|
||||
formData.append('chunk', data.chunk)
|
||||
return adminApi.post<boolean>('/object-storage-file/upload/chunk', formData, {
|
||||
headers: {
|
||||
'Content-Type': 'multipart/form-data'
|
||||
},
|
||||
signal: config?.signal,
|
||||
onUploadProgress: config?.onUploadProgress
|
||||
})
|
||||
},
|
||||
completeChunkUpload: (uploadId: string) => {
|
||||
return adminApi.post<ObjectStorageFileVO>('/object-storage-file/upload/complete', { uploadId }) as unknown as Promise<ObjectStorageFileVO>
|
||||
},
|
||||
cancelChunkUpload: (uploadId: string) => {
|
||||
return adminApi.delete<boolean>(`/object-storage-file/upload/${uploadId}`)
|
||||
},
|
||||
getSignedUrl: (id: number) => {
|
||||
return adminApi.get<string>(`/object-storage-file/get-signed-url/${id}`)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user