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

315
Visualizações
How to upload a file in react typescript with drag and drop?

I am trying to code a drag and drop upload but the not getting anywhere with react typescript. I have a working example but the problem is in google dev tools it is not showing any file.

Here is the code

import { IoCloseSharp, IoChevronForward } from "react-icons/io5";
import { GoCloudUpload } from "react-icons/go";
import { DragEvent, SyntheticEvent } from "react";

type props = {
  onClose: any;
};

const AccountActionsModal = ({ onClose }: props) => {
  const onDropFile = (e: DragEvent) => {
    e.preventDefault();
    const f = e.dataTransfer as DataTransfer
    console.log(f.files);
  };

  return (
    <>
      
            <form>
              <div className="AAFileInput">
                <label
                  htmlFor="Picture"
                  id="AAFileUpload"
                  onDrop={onDropFile}
                  onDragOver={(e) => {
                    e.preventDefault();
                  }}
                  onDragEnter={(e) => {
                    e.preventDefault();
                  }}
                >
                  <GoCloudUpload size={40} />
                  <br />
                  Upload File
                  <br />
                  <span style={{ color: "grey" }}>Drag and Drop</span>
                </label>

                <input type="file" name="Picture" id="Picture" />
              </div>
            </form>
          
    </>
  );
};

export default AccountActionsModal;

You can see I log the filelist but there is no files in the console. It shows 0. I have searched for answers some say that this is a bug in dev tools. because when I log just the event then also it shows 0 files.

FileList {length: 0}

Please help me figuring this out.

about 4 years ago · Juan Pablo Isaza
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