Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

137
Views
Entonces Vs Await problema

No tiene que leer el código, lo que sucede es que un archivo se carga 1000 bytes a la vez. Y para asegurarnos de que enviamos los bytes en el orden en que estamos usando await . ¿Qué pasa si quisiera usar .then() Parece difícil ya que hay un bucle alrededor de la llamada de búsqueda.

 const fileReader = new FileReader(); const theFile = f.files[0]; fileReader.onload = async (ev) => { const CHUNK_SIZE = 5000; const chunkCount = ev.target.result.byteLength / CHUNK_SIZE; console.log("Read successfully"); const fileName = Math.random() * 1000 + theFile.name; for (let chunkId = 0; chunkId < chunkCount + 1; chunkId++) { const chunk = ev.target.result.slice( chunkId * CHUNK_SIZE, chunkId * CHUNK_SIZE + CHUNK_SIZE ); await fetch("http://localhost:8080/upload", { method: "POST", headers: { "content-type": "application/octet-stream", "content-length": chunk.length, "file-name": fileName, }, body: chunk, }); divOutput.textContent = Math.round((chunkId * 100) / chunkCount, 0) + "%"; } console.log(ev.target.result.byteLength); }; fileReader.readAsArrayBuffer(theFile); });
about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

Aquí está la misma funcionalidad sin await . Reemplaza el bucle for :

 const uploadChunk = (chunkId = 0) => { const chunk = ev.target.result.slice( chunkId * CHUNK_SIZE, chunkId * CHUNK_SIZE + CHUNK_SIZE ); fetch("http://localhost:8080/upload", { method: "POST", headers: { "content-type": "application/octet-stream", "content-length": chunk.length, "file-name": fileName, }, body: chunk, }).then(() => { divOutput.textContent = Math.round((chunkId * 100) / chunkCount, 0) + "%"; (chunkId <= chunkCount) && uploadChunk(chunkId + 1); }); } uploadChunk();
about 4 years ago · Juan Pablo Isaza Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!