[英]Firebase functions throwing error when attempting to write to Storage
I have a firebase function which tries to write data to firebase storage:我有一个 firebase function 尝试将数据写入 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);
}
I get a error in the firebase logs which says:我在 firebase 日志中收到一条错误消息:
error TypeError [ERR_INVALID_ARG_TYPE]: The "path" argument must be one of type string, Buffer, or URL. Received type object
错误 TypeError [ERR_INVALID_ARG_TYPE]:“路径”参数必须是字符串、缓冲区或 URL 类型之一。接收到的类型为 object
How do I fix this?我该如何解决?
The error message is pretty explicit: you can only write a string (or the path to a file), a buffer, or URL to a write stream.错误消息非常明确:您只能将字符串(或文件路径)、缓冲区或 URL 写入 stream。
If you want to write the literal string representation of your JSON object to the file, you'll have to convert the object to a string with JSON.stringify(tempJSONObject)
.如果要将 JSON object 的文字字符串表示形式写入文件,则必须将 object 转换为带有
JSON.stringify(tempJSONObject)
的字符串。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.