Node.js 如何将Firebase存储映像获取为base64?
我正在使用Node.js Firebase Cloud函数,但需要获取图像,我将其存储在Firebase Cloud函数中作为base64,以便发送到需要base64的Google Cloud vision APINode.js 如何将Firebase存储映像获取为base64?,node.js,firebase,google-cloud-functions,google-cloud-storage,firebase-storage,Node.js,Firebase,Google Cloud Functions,Google Cloud Storage,Firebase Storage,我正在使用Node.js Firebase Cloud函数,但需要获取图像,我将其存储在Firebase Cloud函数中作为base64,以便发送到需要base64的Google Cloud vision API 怎么做?我根本不知道firebase,但我猜它只是一个API enpoint,您可以调用它来获取图像。如果是这样,您可以下载图像作为arraybuffer,然后更改其格式: const imgUrl = 'https://raw.githubusercontent.com/ianar
怎么做?我根本不知道firebase,但我猜它只是一个API enpoint,您可以调用它来获取图像。如果是这样,您可以下载图像作为
arraybuffer
,然后更改其格式:
const imgUrl = 'https://raw.githubusercontent.com/ianare/exif-samples/master/jpg/Canon_40D.jpg'
const getBase64Img = async () => {
const image = await axios.get(imgUrl, { responseType: "arraybuffer" })
return 'data:image/jpeg;base64,' + Buffer.from(image.data).toString('base64')
}
我根本不知道firebase,但我猜它只是一个API enpoint,您可以调用它来获取图像。如果是这样,您可以下载图像作为
arraybuffer
,然后更改其格式:
const imgUrl = 'https://raw.githubusercontent.com/ianare/exif-samples/master/jpg/Canon_40D.jpg'
const getBase64Img = async () => {
const image = await axios.get(imgUrl, { responseType: "arraybuffer" })
return 'data:image/jpeg;base64,' + Buffer.from(image.data).toString('base64')
}
谢谢回复!但如何使用fs将其存储在本地存储中?您是在节点中还是在浏览器中?节点没有本地存储,但如果要缓存base64字符串,可以使用lru缓存。谢谢回复!但如何使用fs将其存储在本地存储中?您是在节点中还是在浏览器中?节点没有本地存储,但如果要缓存base64字符串,可以使用lru缓存。