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

87
Visualizações
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 à 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