mirror of
https://gitee.com/dapppp/ruoyi-plus-vben5.git
synced 2026-03-10 08:21:09 +08:00
33 lines
707 B
TypeScript
33 lines
707 B
TypeScript
import type { AxiosRequestConfig, AxiosResponse } from 'axios';
|
|
|
|
import type { RequestClient } from '../request-client';
|
|
|
|
class FileUploader {
|
|
private client: RequestClient;
|
|
|
|
constructor(client: RequestClient) {
|
|
this.client = client;
|
|
}
|
|
|
|
public async upload(
|
|
url: string,
|
|
file: Blob | File,
|
|
config?: AxiosRequestConfig,
|
|
): Promise<AxiosResponse> {
|
|
const formData = new FormData();
|
|
formData.append('file', file);
|
|
|
|
const finalConfig: AxiosRequestConfig = {
|
|
...config,
|
|
headers: {
|
|
'Content-Type': 'multipart/form-data',
|
|
...config?.headers,
|
|
},
|
|
};
|
|
|
|
return this.client.post(url, formData, finalConfig);
|
|
}
|
|
}
|
|
|
|
export { FileUploader };
|