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

230
Views
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 answers
Answer question

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 Report
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!