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

108
Visualizações
react-file-drop filter content

I have a question regarding the react-file-drop module. You can see a demo of this module working here. I also provide you the important codesample here:

import React from 'react';
import { FileDrop } from 'react-file-drop';
import './Demo.css';

export const Demo = () => {
  const styles = { border: '1px solid black', width: 600, color: 'black', padding: 20 };
  return (
    <div>
      <h1>React File Drop demo</h1>
      <div style={styles}>
        <FileDrop
          onFrameDragEnter={(event) => console.log('onFrameDragEnter', event)}
          onFrameDragLeave={(event) => console.log('onFrameDragLeave', event)}
          onFrameDrop={(event) => console.log('onFrameDrop', event)}
          onDragOver={(event) => console.log('onDragOver', event)}
          onDragLeave={(event) => console.log('onDragLeave', event)}
          onDrop={(files, event) => console.log('onDrop!', files, event)}
        >
          Drop some files here!
        </FileDrop>
      </div>
    </div>
  );
};

The problem I face currently is that I dont know how to filter the input data which I drop into the container. For example I wish that the module only accepts .csv data or .jpeg data and everything else will be denied. Do you think there is a way to archieve this and if so, how?

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

0

You should be able to handle that in the onDrop callback:

onDrop={(files, event) => {
  const csvFiles = files.filter(file => file.name.endsWith('.csv'));
  console.log('onDrop!', csvFiles, event);
}}
about 4 years ago · Juan Pablo Isaza Relatório

0

You could validate the files in onDrop function.

export const Demo = () => {
  const styles = {
    border: '1px solid black',
    width: 600,
    color: 'black',
    padding: 20,
  }

  const onDrop = (files, event) => {
    if (files[0].type !== 'text/csv' || files[0].type !== 'image/jpeg') {
      alert('Only CSV and JPEG files are allowed')
      return
    }
    // do something with the file
  }

  return (
    <div>
      <h1>React File Drop demo</h1>
      <div style={styles}>
        <FileDrop onDrop={onDrop}>Drop some files here!</FileDrop>
      </div>
    </div>
  )
}

For multiple files you can create an array of allowed filetypes and check if some of the files types are not in the array of allowed types.

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