campose-api / src /utils /downloadFileAsBase64.mts
jbilcke-hf's picture
jbilcke-hf HF staff
initial commit
5b3c62d
raw
history blame
434 Bytes
export const downloadImageAsBase64 = async (remoteUrl: string): Promise<string> => {
const controller = new AbortController()
// download the image
const response = await fetch(remoteUrl, {
signal: controller.signal
})
// get as Buffer
const arrayBuffer = await response.arrayBuffer()
const buffer = Buffer.from(arrayBuffer)
// convert it to base64
const base64 = buffer.toString('base64')
return base64
};