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

239
Vistas
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 Respuestas
Responde la pregunta

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 Denunciar
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