Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

136
Vistas
Waiting for post requests to finish

I'm trying to implement a file upload in Angular. To avoid file size restrictions, I implemented an API endpoint that receives chunks of a file. After all chunks are received another endpoint should be called that reassembles the chunks on the server. Therefor I need to know when all post requests are finished. Preferably without using Promises. The problem is, I'm new to Angular (and even JS) so I'm wondering how this can work.

let i = 0;
for(let offset = 0; offset < file.size; offset += chunkSize) {
  let chunk = file.slice( offset, offset + chunkSize );
  let formData = new FormData();
  formData.append("fileUpload", chunk, file.name + ".part" + i);
  formData.append("identifier", identifier.toString());
  this.http.post(this.baseUrl + "Upload", formData).subscribe();
}
about 4 years ago · Juan Pablo Isaza
1 Respuestas
Responde la pregunta

0

You put these into an array and utilize forkJoin and then subscribe to that.

This will call all the http requests at one time, and the subscribe function will be called once all of them are complete.

let i = 0;
const obsArray = [];
for( let offset = 0; offset < file.size; offset += chunkSize ){
    let chunk = file.slice( offset, offset + chunkSize );

    let formData = new FormData();
      formData.append("fileUpload", chunk, file.name + ".part" + i);
      formData.append("identifier", identifier.toString());
    obsArray.push(
      this.http.post(this.baseUrl + "Upload", formData)
    ).
}
forkJoin(obsArray).subscribe();
about 4 years ago · Juan Pablo Isaza Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda