Created
June 20, 2023 21:09
-
-
Save Aleph-y/642f89203fa0f1b5ff9a406e39232b91 to your computer and use it in GitHub Desktop.
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
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