在 Firebase 中执行文件写入功能时出现 EROFS 错误

EROFS error when executing a File Write function in Firebase

我使用 Firebase 托管了我的网站。但是,我卡住了。

我的想法是创建一个用户页面。当用户单击 "create my page" 时,我想创建一个新页面来保存有关用户的详细信息。用户可以分享新页面的URL给他的朋友,他的朋友应该可以看到他的数据。

我尝试在节点 js 中使用 fs 模块,以便使用云函数编写额外的页面。这种读取数据、写入数据然后将其呈现给用户的方法在本地主机上 运行 时工作得很好。但是,部署网站后,执行该功能时,会抛出“EROFS:只读文件系统”的错误消息。

请提出处理此错误的方法。

Node 的 fs 模块仅用于编写本地文件系统。由于您使用的是 Firebase Functions,FS 的唯一可写部分是 /tmp,如前所述 here. If you want to write to Cloud Storage instead since you need to persist these files, you're going to have to use the Cloud Storage SDK (or the Admin SDK,它包装了 Cloud Storage SDK)。