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

113
Views
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 answers
Answer question

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