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

201
Visualizações
readAsText method of FileReader is returning as undefined in JavaScript, React and material-ui-dropzone

I am trying to get image file as text in one of my JS projects with react. I am using “material-ui-dropzone” package to do user interface. When user drag and drop valid file he has to start button. I am able to get file object in handleSave function. I am passing this file object file reader and then reading as readAsText. But when check the readAsText object (myLogo) in console, it is indicating as undefined can any one help me to revolve it?

codesandbox link is added.

import React from "react";
import Button from "@material-ui/core/Button";
import { DropzoneDialog } from "material-ui-dropzone";

const initialState = {
  open: false,
  files: []
};

// ref: https://github.com/Yuvaleros/material-ui-dropzone
export default function DropzoneDialogExample() {
  const [state, setState] = React.useState(initialState);

  const handleOpen = () => {
    setState({
      ...state,
      open: true
    });
  };

  const handleClose = () => {
    setState({
      ...state,
      open: false
    });
  };

  const handleSave = (files) => {
    setState({
      ...state,
      files: files,
      open: false
    });
    console.log(files.length === 1);
    console.log(files[0]);
    const reader = new FileReader();
    const myLogo = reader.readAsText(files[0]);
    console.log(myLogo);
  };

  return (
    <div>
      <Button
        variant="contained"
        color="primary"
        size="small"
        onClick={handleOpen}
      >
        Add Image
      </Button>
      <DropzoneDialog
        open={state.open}
        onSave={handleSave}
        acceptedFiles={["image/jpeg", "image/png", "image/bmp"]}
        showPreviews={false}
        maxFileSize={5000000}
        onClose={handleClose}
        cancelButtonText={"Cancle"}
        submitButtonText={"Start"}
        showFileNamesInPreview={true}
        dialogTitle={"Select the image file to insert"}
        dropzoneText={"Please Drag and Drop file/s here "}
      />
    </div>
  );
}
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