feat: add progress indicator for uploading files

This commit is contained in:
Elias Schneider
2022-10-12 23:24:11 +02:00
parent 5a9eb58096
commit 8c84d50159
7 changed files with 77 additions and 49 deletions

View File

@@ -68,10 +68,20 @@ const downloadFile = async (shareId: string, fileId: string) => {
window.location.href = await getFileDownloadUrl(shareId, fileId);
};
const uploadFile = async (shareId: string, file: File) => {
const uploadFile = async (
shareId: string,
file: File,
progressCallBack: (uploadingProgress: number) => void
) => {
var formData = new FormData();
formData.append("file", file);
return (await api.post(`shares/${shareId}/files`, formData)).data;
return (
await api.post(`shares/${shareId}/files`, formData, {
onUploadProgress: (progressEvent) =>
progressCallBack(progressEvent.loaded),
})
).data;
};
export default {