【发布时间】:2022-02-09 06:45:32
【问题描述】:
我正在尝试在 firebase 函数中读取 csv 文件,以便我可以处理该文件并使用数据执行其余操作。
import * as csv from "csvtojson";
const csvFilePath = "<gdrive shared link>"
try{
console.log("First Method...")
csv()
.fromFile(csvFilePath)
.then((jsonObj: any)=>{
console.log("jsonObj....",JSON.stringify(jsonObj));
})
console.log("Second Method...")
const jsonArray=await csv().fromFile(csvFilePath);
console.log("jsonArray...", JSON.stringify(jsonArray))
}
catch(e){
console.log("error",JSON.stringify(e))
}
上述是我尝试读取 csv 的 2 种方法,但都显示 firebase 错误
'错误:文件不存在。检查以确保 csv 的文件路径正确。'
如果是“csvFilePath”,我尝试了 2 种方法
-
只是在函数的同一文件夹中添加了csv文件并添加了类似的代码
const csvFilePath = "./student.csv" -
将相同的文件添加到谷歌驱动器并将访问权限更改为任何拥有该链接的人都可以读取和编辑并给出相同的路径
const csvFilePath = "<gdrive shared link>"
两者都显示相同的错误。如果是谷歌驱动器,我不想使用任何类型的谷歌凭据,因为我打算在 firebase 函数中读取一个简单的 csv 文件。
【问题讨论】:
-
对我来说同样的问题。任何帮助将不胜感激。
-
嗨!您能否分享对我的回答的反馈,以了解是否需要进一步的帮助?
标签: json firebase csv google-cloud-functions