Created
May 12, 2021 05:07
-
-
Save hungdoansy/aed01026e2a03201f2fef0a265cfeaab to your computer and use it in GitHub Desktop.
Convert remote image into base64 with axios
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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