Files
admin-vben5/apps/web-antd/src/api/core/upload.ts

48 lines
1.1 KiB
TypeScript
Raw Normal View History

2025-06-18 11:03:42 +08:00
import type { AxiosRequestConfig } from '@vben/request';
import { requestClient } from '#/api/request';
/**
* Axios上传进度事件
*/
export type AxiosProgressEvent = AxiosRequestConfig['onUploadProgress'];
/**
*
*/
export interface UploadResult {
url: string;
fileName: string;
ossId: string;
}
/**
*
* @param file
* @param options
* @param options.onUploadProgress
* @param options.signal
* @param options.otherData
* @returns
*/
export function uploadApi(
file: Blob | File,
options?: {
onUploadProgress?: AxiosProgressEvent;
otherData?: Record<string, any>;
signal?: AbortSignal;
},
) {
const { onUploadProgress, signal, otherData = {} } = options ?? {};
return requestClient.upload<UploadResult>(
'/resource/oss/upload',
{ file, ...otherData },
{ onUploadProgress, signal, timeout: 60_000 },
);
}
/**
* api type
*/
export type UploadApi = typeof uploadApi;