[英]Downloading excel file from Google Cloud storage returns a buffer, how can I return the actual excel file so I can write to it in my handler?
I'm trying to retrieve an excel file from my bucket using the Firebase Admin SDK using the following code:我正在尝试使用 Firebase Admin SDK 从我的存储桶中检索 excel 文件,代码如下:
export const getTemplate = async (fileName: string) => {
const filePath = admin
.storage()
.bucket()
.file('sheets/template.xlsx')
const [file] = await filePath.download()
return file
}
I then pass what's returned from this function, to this function:然后我将从这个 function 返回的内容传递给这个 function:
export const writeToTemplate = (
objects: any[],
sheetNames: string[],
file
) => {
objects.forEach((dataObject, index) => {
const sheetName = sheetNames[index]
const worksheet = templateFile.Sheets[sheetName]
utils.sheet_add_json(worksheet, dataObject)
})
return file
}
However this throws an error that it cannot read my file.但是,这会引发一个错误,即它无法读取我的文件。 When I console log the file it shows a buffer
当我控制台记录文件时,它显示一个缓冲区
<Buffer 50 4b 03 04 14 00 06 00 08 00.........>
How can I actually write to the file?我怎样才能真正写入文件? Cheers:)
干杯:)
I needed to read the Buffer with the read function from the 'xlsx' package!我需要从“xlsx”包中读取 function 来读取缓冲区!
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.