I'm trying write angular app to send sliced file to backend.
What I'm doing with file:
- Cut multiple files to array (every slice have 1MB)
const array = [];
for (let i = 0; i < this.File.file.size; i += 1048576) {
array.push(this.File.file.slice(i, i + 1048576));
}
- For every file call fuction UploadAllSlices()
private UploadAllSlices() {
let sliceNumber = 0;
const fileUploadSub: Subject<void> = new Subject();
const chunkObserver = new Observable(observer => {
const chunkUploadSub: Subscription = fileUploadSub.subscribe(
_ => {
this.uploadFile(sliceNumber).subscribe((chunkReponse: any) => {
// my logic here
},
e => {
console.log('ERROR', e);
}
);
sliceNumber++;
fileUploadSub.next();
});
}).pipe(
takeUntil(this.pause$),
retry(1000)
);
}
- Function uploadFile (using inside UploadAllSlices())
private uploadFile (index: number) {
const formData = new FormData();
formData.append(); // other data not important
formData.append(); // other data not important
formData.append('SliceContent', this.File.array[index]);
return this.http.patch(URL , formData).pipe(
retry(1000),
takeUntil(this.pause$)
);
}
When i upload 1-3 files everything work perfect. But when i try upload 10-15 files in one time some files randomly stuck. ( sometimes all files are uploaded, sometimes 1-2 files stuck, sometimes 5 files stuck its very randomly)
for those files that stuck
this.http.patch is not being executed so I can't get response and make my logic here:
this.uploadFile(sliceNumber).subscribe((chunkReponse: any) => {
// logic here
}
Any idea why it's stuck randomly, and why subscribe doesn't send http.patch to backend?