Some checks failed
Branch Build CE / Build Setup (push) Has been cancelled
Branch Build CE / Build-Push Admin Docker Image (push) Has been cancelled
Branch Build CE / Build-Push Web Docker Image (push) Has been cancelled
Branch Build CE / Build-Push Space Docker Image (push) Has been cancelled
Branch Build CE / Build-Push Live Collaboration Docker Image (push) Has been cancelled
Branch Build CE / Build-Push API Server Docker Image (push) Has been cancelled
Branch Build CE / Build-Push Proxy Docker Image (push) Has been cancelled
Branch Build CE / Build-Push AIO Docker Image (push) Has been cancelled
Branch Build CE / Upload Build Assets (push) Has been cancelled
Branch Build CE / Build Release (push) Has been cancelled
CodeQL / Analyze (javascript) (push) Has been cancelled
CodeQL / Analyze (python) (push) Has been cancelled
Codespell / Check for spelling errors (push) Has been cancelled
Sync Repositories / sync_changes (push) Has been cancelled
Synced from upstream: 8853637e981ed7d8a6cff32bd98e7afe20f54362
41 lines
992 B
TypeScript
41 lines
992 B
TypeScript
import type { AxiosRequestConfig } from "axios";
|
|
import axios from "axios";
|
|
// services
|
|
import { APIService } from "@/services/api.service";
|
|
|
|
export class FileUploadService extends APIService {
|
|
private cancelSource: any;
|
|
|
|
constructor() {
|
|
super("");
|
|
}
|
|
|
|
async uploadFile(
|
|
url: string,
|
|
data: FormData,
|
|
uploadProgressHandler?: AxiosRequestConfig["onUploadProgress"]
|
|
): Promise<void> {
|
|
this.cancelSource = axios.CancelToken.source();
|
|
return this.post(url, data, {
|
|
headers: {
|
|
"Content-Type": "multipart/form-data",
|
|
},
|
|
cancelToken: this.cancelSource.token,
|
|
withCredentials: false,
|
|
onUploadProgress: uploadProgressHandler,
|
|
})
|
|
.then((response) => response?.data)
|
|
.catch((error) => {
|
|
if (axios.isCancel(error)) {
|
|
console.log(error.message);
|
|
} else {
|
|
throw error?.response?.data;
|
|
}
|
|
});
|
|
}
|
|
|
|
cancelUpload() {
|
|
this.cancelSource.cancel("Upload canceled");
|
|
}
|
|
}
|