Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

342
Visualizações
how to accept only apk file in react js?
import React from "react";
export default function DropDown() {
  const changeHandler=()=>{
    let value=document.getElementById('someId');
    let ext = value.match(/\.([^\.]+)$/)[1];
    switch (ext) {
      case 'apk':
        alert('Allowed');
        break;
      default:
        alert('Not allowed');
        value = '';
    }
  };
return (
    <>
     <input type="file" id="someId" accept=".apk" onChange={changeHandler} />
    </>
  );
}

after selecting file it throws error value.match is not a function. how to resolve that if we click upload button if we upload apk file popup throws allow or else popup is not allowed

about 4 years ago · Juan Pablo Isaza
1 Respostas
Responde à pergunta

0

The accept=".apk" prop in the first place if it is supported by the browser would not allow non .apk files.

If you really want to get the actual filename with the extension, the event handler itself passes an event object. You just need to access the target of that event in your change handler.

const changeHandler=(e)=>{
  const filename = e.target.files[0].name; // filename.apk
  // do whatever you want.
}

you may also use e.target.files[0].type will also show what filename type was chosen.

about 4 years ago · Juan Pablo Isaza Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda