Navigation Menu

Skip to content

Instantly share code, notes, and snippets.

@hungdoansy
Created May 12, 2021 05:07
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save hungdoansy/aed01026e2a03201f2fef0a265cfeaab to your computer and use it in GitHub Desktop.
Save hungdoansy/aed01026e2a03201f2fef0a265cfeaab to your computer and use it in GitHub Desktop.
Convert remote image into base64 with axios
const getBase64 = async url => {
const response = await axios.get(url, {
responseType: 'arraybuffer',
});
const imageType = response.headers['content-type'];
const base64 = Buffer.from(response.data, 'binary').toString('base64');
const dataURI = `data:${imageType};base64,${base64}`;
return dataURI;
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment