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

193
Views
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
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!