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
Cómo usar jquery obtener JSON desde el backend y actualizar innerHTML en el frontend

Esto está en mi 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>

Y esto está en mi 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); }); }

Estoy tratando de cargar un archivo y almacenarlo en la cadena de bloques de IPFS, y luego cargar el hash de ese archivo en el front-end.

Lo que esto debería permitirme hacer es cargar archivos PDF, videos, música e imágenes, y almacenarlos todos en la cadena de bloques y luego implementarlos en el sitio.

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!