Download packages/effects/request/src/request-client/modules/uploader.ts from binhugg3/admin: direct link, hf CLI and curl.
- Browser
- Download file 801 Bytes
-
https://huggingface.co/spaces/binhugg3/admin/resolve/main/packages/effects/request/src/request-client/modules/uploader.ts
- Command line
-
hf download hf://spaces/binhugg3/admin/packages/effects/request/src/request-client/modules/uploader.ts
-
curl -L -o uploader.ts https://huggingface.co/spaces/binhugg3/admin/resolve/main/packages/effects/request/src/request-client/modules/uploader.ts
801 Bytes
| 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, | |
| data: { file: Blob | File } & Record<string, any>, | |
| config?: AxiosRequestConfig, | |
| ): Promise<AxiosResponse> { | |
| const formData = new FormData(); | |
| Object.entries(data).forEach(([key, value]) => { | |
| formData.append(key, value); | |
| }); | |
| const finalConfig: AxiosRequestConfig = { | |
| ...config, | |
| headers: { | |
| 'Content-Type': 'multipart/form-data', | |
| ...config?.headers, | |
| }, | |
| }; | |
| return this.client.post(url, formData, finalConfig); | |
| } | |
| } | |
| export { FileUploader }; | |