I am trying to build a component which basically does two things:
- Split the file into smaller blobs
- Upload the file parts, once all the parts are uploaded then make an API call and mark the item as upload completed.
So far, I have been able to create an end-to-end poc, but I am trying to improve on my code to upload only n chunks at a time then proceed to next batch and wait until all chunks are uploaded.
For the splitting logic I am using, bufferCount + forkJoin but I want to be able to call an API after all chunks are complete. Instead, it gets triggered after each batch completes.
- The next batch should not get triggered if the previous batch fails.
const apiCallouts = parts.map((part, idx) => {
const formData = new FormData();
formData.append('part', part);
const opts = { ...baseOptions(this.conf) };
delete opts.headers['content-type'];
return this.http.put(// Perform API Callout)
});
const mergeObs = from(apiCallouts).pipe(
bufferCount(5),
concatMap(buffer => forkJoin(buffer))
);
What would be the best way to go about this?