node.js - 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 日志中收到一条错误消息:
error TypeError [ERR_INVALID_ARG_TYPE]:“路径”参数必须是字符串、缓冲区或 URL 类型之一。接收到的类型对象
我该如何解决?
解决方案
错误消息非常明确:您只能将字符串(或文件的路径)、缓冲区或 URL 写入写入流。
如果要将 JSON 对象的文字字符串表示形式写入文件,则必须将对象转换为带有JSON.stringify(tempJSONObject)
.
推荐阅读
- python - 为什么我的 nginx 服务器上的 pycurl 响应与我计算机上的响应不同
- java - 哪个 HTTP 状态代码对于订阅取消异常是正确的?
- mysql - 如何计算单独的列?
- three.js - Three.js - 在特定 position.x,z 处获取网格的地形高度(position.y) - 没有鼠标和光线投射器?
- php - 将 MSRP 添加到 WooCommerce 的产品页面
- typescript - 在反应本机应用程序中处理非空断言
- shiny - 我可以向渲染表添加多个表达式吗?
- javascript - Firebase 和 Angular:切换页面时在屏幕上显示旧数据
- c# - 当我尝试打印时,为什么我的条形码图像不适合条形码打印机设置中指定的纸张尺寸?
- android-studio - ✗ Android 许可证状态未知