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

90
Views
¿Cómo podría verificar si el archivo tiene una extensión deseable al cargar un archivo en Javascript/FileApi?

Entonces, lo que está sucediendo es que estoy un poco atascado con las extensiones de fileApi, no puedo ver cómo debo mostrar la alerta cuando el archivo de carga no es .pdf , por ejemplo. Realmente me encantaría alguna orientación. Gracias

 Html <form action="/Document" method="post" enctype="multipart/form-data"> <div class="container"> <div class="custom-file" style="margin-top: 25px; margin-bottom: 15px;"> <input type="file" id="validatedCustomFile" name="document" required> <div style="color: red;"></div> </div> <div class="small"> <ul> <li>Maximum upload size is / 1024) KB</li> </ul> </div> <div> <button type="submit" title="Next" class="btn btn-primary">Next</button> </div> </div> </form>
 <script> Js const InputFile = document.getElementById('validatedCustomFile'); InputFile.addEventListener("change", function () { console.log(InputFile.files) for (const file of InputFile.files) { if (file.size > 1048576){ alert(`${file.name} is to big! Max is 1024KB`); } if (file.type != '.pdf') { alert('This file type not allowed to be uploaded') } } } ) </script>
about 4 years ago · Juan Pablo Isaza
2 answers
Answer question

0

Hay un método simple para hacerlo, simplemente agregando a su formulario input accept=".pdf" La página de carga solo mostrará el archivo con la extensión .pdf y ocultará el resto. Algo como esto: <input type="file" id="validatedCustomFile" accept=".pdf" name="document" required> funcionaría.

about 4 years ago · Juan Pablo Isaza Report

0

aquí, debe configurar el tipo de archivo mime. Aquí, mencioné application/pdf en lugar de ".pdf"

 const InputFile = document.getElementById('validatedCustomFile'); InputFile.addEventListener("change", function () { console.log(InputFile.files) for (const file of InputFile.files) { if (file.size > 1048576){ alert(`${file.name} is to big! Max is 1024KB`); } if (file.type != 'application/pdf') { alert('This file type not allowed to be uploaded') } } } )

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!