Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

92
Vistas
I can't upload after implementing image preview - react js

i have a form that upload files and store data and its working fine and upload files to storage but whenever i try to preview the image during upload it show this error after i press submit:

error - unhandledRejection: TypeError: Cannot read properties of undefined (reading 'path')

so the working code is as follow:

const state = {
selectedFile5: null,
};

function fileUploadHandler5(event) {
state.selectedFile5 = event.target.files[0];
}

const sendFileToServer = async (file5) => {
const formData = new FormData();
formData.append( "file5",file5);
...
<input name="file5" onChange={fileUploadHandler5} type="file" className="custom-file-input" id="shop-logo" />

the above code is working fine but when i try to implement the image preview as follow:

const [selectedImage, setSelectedImage] = useState();
function fileUploadHandler5(event) {
state.selectedFile5 = event.target.files[0];
setSelectedImage(state.selectedFile5);
}

const removeSelectedImage = () => {
setSelectedImage();
};
...
<Col xs="12" sm="6" className="pt-3">
      {selectedImage && (
      <div>
        <img
          src={URL.createObjectURL(selectedImage)}
          alt="Thumb"
        />
        <button onClick={removeSelectedImage}>
          Remove This Image
        </button>
      </div>
    )}
      </Col>
      <Col xs="12" sm="6" className="pt-3">
        <label for="shop-logo">Shop Logo</label>
        <div className="custom-file">
          <input name="file5" onChange={fileUploadHandler5} type="file" className="custom-file-input" id="shop-logo" />
          <label className="custom-file-label" for="shop-logo">
            Choose file
          </label>
        </div>
      </Col>

the image preview will work but i can't submit because of the error above

what am i doing wrong?

about 4 years ago · Juan Pablo Isaza
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda