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

334
Vistas
Lea, edite los datos y descargue múltiples archivos en JavaScript puro

En primer lugar, permito que los usuarios carguen varios archivos. Luego uso bucle con fileReader para leer todos los archivos cargados. Luego edito algunos datos de cada archivo y creo nuevos archivos que contienen cada dato. Finalmente, quiero descargar todos estos archivos usando la biblioteca fileSaver. El problema es que solo puedo descargar el último archivo con el siguiente código. Estaría muy agradecido si alguien puede arreglarlo. Código:

 <html> <body> <!-- Link to FileSaver Library --> <script src="https://cdnjs.cloudflare.com/ajax/libs/FileSaver.js/2.0.5/FileSaver.min.js" integrity="sha512-Qlv6VSKh1gDKGoJbnyA5RMXYcvnpIqhO++MhIM2fStMcGT9i2T//tSwYFlcyoRRDcDZ+TYHpH8azBBCyhpSeqw==" crossorigin="anonymous" referrerpolicy="no-referrer"></script> <!-- Allow users to upload multiple files --> <input type="file" id="real-file" accept=".xml" multiple/> <script> const realFileBtn = document.getElementById("real-file") realFileBtn.addEventListener("change", function() { if (realFileBtn.value) { // Use loop to do for all uploaded files for(var i = 0; i < realFileBtn.files.length; i++){ var fr = new FileReader() var fileName = realFileBtn.files[i].name fr.readAsText(realFileBtn.files[i]) fr.onload = function() { // After loading the file, I get the data of it and edit some information (for example: replace "a" with "b") var data = fr.result.replaceAll("a", "b") // I create a new file that contain the edited data with the same name as the uploaded file var myFile = new File( [data], fileName, {type: "text/xml; charset = utf8"}) // Then I download that file saveAs(myFile) // The issue is that I can only download 1 file and that file is the last file you uploaded // I want to read the first file, edit its data and download the file contain that data. Then do the same with second file, // third file,... n file } } } }) </script> </body>
about 4 years ago · Juan Pablo Isaza
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