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

107
Visualizações
Convert svg image from url to base64 in node

I would like to use svg image that I have from url, convert it to base64. Later on I am posting this image on social media platform. That is why I need it to be in base64 format. How can I achieve that? I know how to do that when I have this picture on my website but how can I do that when I have only a link to that image?

about 4 years ago · Juan Pablo Isaza
1 Respostas
Responde à pergunta

0

Here is the simple code which can be used in node.js using node-fetch library.

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);
})();

I'm using sample svg image from this link. Above code will return you base64 of the sample svg image :

PHN2ZyB4bWxucz0iaHR0cDovL3d3dy53My5vcmcvMjAwMC9zdmciIHZpZXdCb3g9IjAgMCAxMDAgMTAwIj4KICA8cGF0aCBkPSJNMzAsMWg0MGwyOSwyOXY0MGwtMjksMjloLTQwbC0yOS0yOXYtNDB6IiBzdHJva2U9IiMwMDAiIGZpbGw9Im5vbmUiLz4gCiAgPHBhdGggZD0iTTMxLDNoMzhsMjgsMjh2MzhsLTI4LDI4aC0zOGwtMjgtMjh2LTM4eiIgZmlsbD0iI2EyMyIvPiAKICA8dGV4dCB4PSI1MCIgeT0iNjgiIGZvbnQtc2l6ZT0iNDgiIGZpbGw9IiNGRkYiIHRleHQtYW5jaG9yPSJtaWRkbGUiPjwhW0NEQVRBWzQxMF1dPjwvdGV4dD4KPC9zdmc+Cg==

If you copy and paste this here, you will see the preview of the same image. Voila !!

about 4 years ago · Juan Pablo Isaza Relatório
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