Skip to content

Instantly share code, notes, and snippets.

@Aleph-y
Created June 20, 2023 21:09
Show Gist options
  • Save Aleph-y/642f89203fa0f1b5ff9a406e39232b91 to your computer and use it in GitHub Desktop.
Save Aleph-y/642f89203fa0f1b5ff9a406e39232b91 to your computer and use it in GitHub Desktop.
async function getImageData() {
try {
const response = await axios.get('https://tu-endpoint.com', {
headers: {
'Authorization': 'Bearer tu_token_de_autorizacion'
},
responseType: 'arraybuffer' // Especifica el tipo de respuesta como un arraybuffer
});
const imgData = Buffer.from(response.data, 'binary').toString('base64');
const imgSrc = `data:image/png;base64,${imgData}`;
return imgSrc;
} catch (error) {
console.error(error);
return null;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment