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

76
Views
crear un archivo descargable para dispositivos móviles y de escritorio

Quiero crear una vCard en la interfaz y hacerla descargable (haciendo clic en un botón) en un Proyecto ReactJs. Uso un módulo de NodeJS llamado vcards-js que crea una cadena con el contenido de la vCard deseada (v3.0). Lo que me cuesta es hacerlo descargable (como archivo .vcf).

aquí está mi código

 const {fname,lname,phoneNumber,email,organisation,title}=req.body const mycard=vcard() mycard.firstName=fname mycard.lastName=lname mycard.phoneNumber=phoneNumber mycard.email=email mycard.organisation=organisation mycard.title=title // enter code here console.log(mycard.getFormattedString(),"utf-8")

después de console.log() obtengo datos de formato vcard pero cómo descargarlos; por favor escribe los pasos

about 4 years ago · Juan Pablo Isaza
2 answers
Answer question

0

Creo que sus preguntas están respondidas aquí . Para traducir esta respuesta a su ejemplo, sería algo como esto:

 var textFile = null, makeTextFile = function (text) { var data = new Blob([text], {type: 'text/plain'}); // If we are replacing a previously generated file we need to // manually revoke the object URL to avoid memory leaks. if (textFile !== null) { window.URL.revokeObjectURL(textFile); } textFile = window.URL.createObjectURL(data); // returns a URL you can use as a href return textFile; }; // ------------- var create = document.getElementById('create'); create.addEventListener('click', function () { var link = document.createElement('a'); link.setAttribute('download', 'XXXXX.vcf' /* set your vcf name here*/); link.href = makeTextFile( mycard.getFormattedString() ); document.body.appendChild(link); // wait for the link to be added to the document window.requestAnimationFrame(function () { var event = new MouseEvent('click'); link.dispatchEvent(event); document.body.removeChild(link); }); }, false);

about 4 years ago · Juan Pablo Isaza Report

0

Yo mismo no he usado vcard.js, pero al leer el LÉAME en github ( https://github.com/enesser/vCards-js#on-the-web ) solo redirige al usuario a la URL del punto final donde genera la tarjeta virtual. Algo como esto:

nodos:

 var express = require('express'); var router = express.Router(); module.exports = function (app) { app.use('/vcard', router); }; router.get('/', function (req, res, next) { var vCardsJS = require('vcards-js'); var vCard = vCardsJS(); // Create your vcard here res.send(vCard.getFormattedString()); });

Interfaz:

 window.location = "/vcard"
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!