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

231
Visualizações
How to display uploaded file content using context.api?

i need to display content of the file i choose inside file selector. I have displayed it's name on navbar and when i click on it's name it takes me to the ther blank tab in which i need to have it's content displayed. I need to have only pdf and jpeg file types enabled, not other. This uploading component is rendered inside one page, which is then rendered inside app component. Here is my code for uploader:

import React, { useState, useEffect, useContext } from "react";
import { useDropzone } from "react-dropzone";
import Upload from "./pictures/fileUpload.png";
import { fileContext } from "../context/context";

function Uploading() {
  const { setFileName } = useContext(fileContext);

  const { getRootProps, getInputProps, acceptedFiles } = useDropzone({
    noDrag: true,
  });

  // Logging the selected files to the console. //
  console.log(acceptedFiles);

  useEffect(() => {
    if (acceptedFiles.length === 0) {
      console.log("No Uploaded Files. Upload .pdf or .jpeg file !");
    } else {
      setFileName(acceptedFiles[0].name);
      window.localStorage.setItem("fileName", `${acceptedFiles[0].name}`);
    }
  }, [acceptedFiles]);

  return (
    <section className="container w-full h-full text-center">
      <div {...getRootProps({ className: "dropzone h-full" })}>
        <input
          {...getInputProps()}
          type="file"
        />
        <img src={Upload} className="mx-auto cursor-pointer " alt="" />
        <label class="text-2xl">Choose Document</label>
      </div>
    </section>
  );
}

export default Uploading;
about 4 years ago · Juan Pablo Isaza
1 Respostas
Responde à pergunta

0

You can use simple JavaScript for that.

let file = $('#photo')[0].files[0];
let reader = new FileReader();
reader.readAsArrayBuffer(file);
reader.onload = function(e){
  let blob = new Blob([e.target.result]);
  window.URL = window.URL || window.webkitURL;
  let blobURL = window.URL.createObjectURL(blob);
  let image = new Image();
  image.src = blobURL;
  image.onload = function() {
    //add the image element to the target container
  }
}

Sorry for not showing exactly what you wanted. I've showed how you can get image element after file upload and then do stuff with it.

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