提问者:小点点

Firebase函数在尝试写入存储时抛出错误


我有一个firebase函数尝试将数据写入firebase存储:

const bucket = admin.storage().bucket(/*removed for this question*/);
var tempJSONObject = {
 testing: "why are we testing",
 anothertest:"constanttesting"
}
try{
const fileName = `storedjokes/81.json`
const file = bucket.file(fileName);
const writeStream = fs.createWriteStream(file);
writeStream.write(tempJSONObject,(err) => {
 if(err){
   console.log(err.message);
 }else{
   console.log("data written");
 }
});
}catch(e){
 console.log('error',e);
}

我在firebase日志中发现一个错误,它说:

错误类型错误[ERR_INVALID_ARG_TYPE]:“path”参数必须是string、Buffer或URL类型之一。接收类型对象

我怎么解决这个?


共1个答案

匿名用户

错误消息非常明确:您只能将字符串(或文件的路径)、缓冲区或URL写入写流。

如果要将JSON对象的文字字符串表示形式写入文件,则必须使用JSON.stringify(tempJSONObject)将对象转换为字符串。