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

106
Views
Convierta la imagen svg de url a base64 en el nodo

Me gustaría usar la imagen svg que tengo de url , convertirla a base64 . Más tarde estoy publicando esta imagen en la plataforma de redes sociales. Por eso necesito que esté en formato base64 . ¿Cómo puedo lograr eso? Sé cómo hacerlo cuando tengo esta imagen en mi sitio web, pero ¿cómo puedo hacerlo cuando solo tengo un enlace a esa imagen?

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

0

Aquí está el código simple que se puede usar en node.js usando la biblioteca node-fetch .

 import fetch from 'node-fetch'; const download = async () => { const response = await fetch("https://dev.w3.org/SVG/tools/svgweb/samples/svg-files/410.svg"); if (response.ok) { const buffer = await response.buffer(); const base64 = buffer.toString("base64"); return base64; } } (async () => { const data = await download(); console.log("🚀 ~ file: base64.js ~ line 12 ~ data", data); })();

Estoy usando una imagen svg de muestra de este enlace . El código anterior le devolverá la base64 de la imagen svg de muestra:

 PHN2ZyB4bWxucz0iaHR0cDovL3d3dy53My5vcmcvMjAwMC9zdmciIHZpZXdCb3g9IjAgMCAxMDAgMTAwIj4KICA8cGF0aCBkPSJNMzAsMWg0MGwyOSwyOXY0MGwtMjksMjloLTQwbC0yOS0yOXYtNDB6IiBzdHJva2U9IiMwMDAiIGZpbGw9Im5vbmUiLz4gCiAgPHBhdGggZD0iTTMxLDNoMzhsMjgsMjh2MzhsLTI4LDI4aC0zOGwtMjgtMjh2LTM4eiIgZmlsbD0iI2EyMyIvPiAKICA8dGV4dCB4PSI1MCIgeT0iNjgiIGZvbnQtc2l6ZT0iNDgiIGZpbGw9IiNGRkYiIHRleHQtYW5jaG9yPSJtaWRkbGUiPjwhW0NEQVRBWzQxMF1dPjwvdGV4dD4KPC9zdmc+Cg==

Si copia y pega esto aquí , verá la vista previa de la misma imagen. ¡Voila!

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!