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