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

229
Views
How to use jquery get JSON from the backend and update innerHTML on the frontend

This is in my index.ejs

<script src="https://cdn.jsdelivr.net/npm/ipfs-core/dist/index.min.js"></script>
<script>
      async function saveFile(file) {
        const node = window.IpfsCore.create();
        return await node.files.add(file);
      }
      function receivedText() {
        document.getElementById('ipfs').appendChild(document.createTextNode(fr.result));
      } 

      async function readfichier(e) {
        if(window.FileReader) {
          var file  = e.target.files[0];
          var reader = new FileReader();
          if (file && file.type.match('image.*')) {
            reader.readAsDataURL(file);
          }
          reader.onloadend = function (e) {
          }
          console.log(file);
          document.getElementById('fileNameOutput').innerHTML = document.getElementById('fileName').value;
          document.getElementById('ipfs').innerHTML = await saveFile(JSON.stringify(file));
        }
      }     
      function clickme() {
          $('file').ready(function(){ const file = $('file').prop('files')});
          var fr = new FileReader();
          fr.onload = select;
          document.getElementById('file').addEventListener('change', readfichier, false);

          //fr.readAsText(file);
          //fr.readAsBinaryString(file); //as bit work with base64 for example upload to server
          
        }
        function select() {

           var id = $('file').prop('files');
           $.getJSON("/upload?" + $.param(id), function (res) {
              document.getElementById('ipfs').innerHTML = res;
            });
           
      }
    </script>

And this is in my index.js

app.get('/upload', async (req,res) => {
    const file = req.files.file;
    const fileHash = await saveFile(JSON.stringify(file));
    res.send(fileHash)
})
function success(result){
    return result
}
async function saveFile(file) {
    await ipfs.add(file, (err, result) => {
        if (err){
            console.log(err);
        }
        console.log(result);
    });
}

I'm trying to upload a file and store it on the IPFS blockchain, and then load the hash of that file into the front-end.

What this should enable me to do is to load PDFs and Videos and Music and Images, and store them all on the blockchain and then implement them all onsite.

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