简体   繁体   English

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

[英]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.

相关问题 Firebase function 尝试写入 firebase 存储“Firebase 存储:用户无权访问”时出错 - Firebase function getting error when trying to write to firebase storage "Firebase Storage: User does not have permission to access" 新创建的 Firebase 函数抛出 UNAUTHENTICATED 错误 - Newly Created Firebase Functions Throwing UNAUTHENTICATED Error 当我尝试初始化 firebase 应用程序时,为什么 Google Cloud Functions 会抛出“配置 firebase.databaseURL 的无效值”错误? - Why is Google Cloud Functions throwing a "Invalid value for config firebase.databaseURL" error when I try to initialize a firebase app? FirebaseCommandException:尝试运行命令时 Firebase CLI 发生错误 - FirebaseCommandException: An error occured on the Firebase CLI when attempting to run a command 尝试将图像上传到 Firebase 存储时出错 - Error when trying to upload images to Firebase storage 带有模拟器的 Firebase 函数和存储 getSignedUrl - Firebase Functions and Storage getSignedUrl with Emulators 加载 Map 视图时 React Native Firebase 抛出错误 - React Native Firebase Throwing Error when Map view is loaded 错误:内部 firebase 函数,与 nodemailer 一起使用时 - Error:INTERNAL firebase functions ,when using it with nodemailer Firebase 调用 Stripe 时函数出错 - Firebase Functions error when calling Stripe 从firebase函数上传数据到firebase存储? - Uploading data from firebase functions to firebase storage?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM