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

232
Vistas
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
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